ExcelCsv.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpersTests » CommonTests » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » FileHelpers Library 
FileHelpers Library » FileHelpersTests » CommonTests » ExcelCsv.cs
using System;
using System.Collections;
using System.IO;
using FileHelpers;
using NUnit.Framework;

namespace FileHelpersTests.CommonTests{
  [TestFixture]
  public class ExcelCsv
  {

    FileHelperEngine engine;

    [Test]
    public void ReadExcelCsv1()
    {
      engine = new FileHelperEngine(typeof (ExcelCsv1Type));

      ExcelCsv1Type[] res = (ExcelCsv1Type[]) Common.ReadTest(engine, @"Good\ExcelCsv1.txt");

      Assert.AreEqual(4, res.Length);

      Assert.AreEqual("AllwaysOnTop", res[0].OrganizationName);
      Assert.AreEqual("COMPUTERS, HARDWARE", res[1].OrganizationName);
      Assert.AreEqual("4S Consulting, Inc.", res[2].OrganizationName);
      Assert.AreEqual("SmartSolutions", res[3].OrganizationName);

      Assert.AreEqual("Test 1,", res[0].TestField);
      Assert.AreEqual("Test, 2", res[1].TestField);
      Assert.AreEqual(" Test 3", res[2].TestField);
      Assert.AreEqual("Test 4", res[3].TestField);
      
    }

    [Test]
    public void ReadExcelCsv2()
    {
      engine = new FileHelperEngine(typeof (ExcelCsv2Type));

      ExcelCsv2Type[] res = (ExcelCsv2Type[]) Common.ReadTest(engine, @"Good\ExcelCsv2.txt");

      Assert.AreEqual(4, res.Length);

      Assert.AreEqual("AllwaysOnTop", res[0].OrganizationName);
      Assert.AreEqual("COMPUTERS, HARDWARE", res[1].OrganizationName);
      Assert.AreEqual("4S Consulting, Inc.", res[2].OrganizationName);
      Assert.AreEqual("SmartSolutions", res[3].OrganizationName);

      Assert.AreEqual("Test 1,", res[0].TestField);
      Assert.AreEqual("Test, 2", res[1].TestField);
      Assert.AreEqual(" Test 3", res[2].TestField);
      Assert.AreEqual("Test 4", res[3].TestField);
      
    }

    [Test]
    public void WriteExcelCsv1()
    {
      ArrayList arr = new ArrayList();
      ExcelCsv1Type record;

      record = new ExcelCsv1Type();
      record.OrganizationName = "AllwaysOnTop";
      record.TestField = "Test 1,";
      arr.Add(record);

      record = new ExcelCsv1Type();
      record.OrganizationName = "COMPUTERS, HARDWARE";
      record.TestField = "Test, 2";
      arr.Add(record);

      record = new ExcelCsv1Type();
      record.OrganizationName = "4S Consulting, Inc.";
      record.TestField = " Test 3";
      arr.Add(record);

      record = new ExcelCsv1Type();
      record.OrganizationName = "SmartSolutions";
      record.TestField = "Test 4";
      arr.Add(record);

      engine = new FileHelperEngine(typeof (ExcelCsv1Type));

      string tmp = engine.WriteString(arr.ToArray());
      ExcelCsv1Type[] res = (ExcelCsv1Type[]) engine.ReadString(tmp);
            
      Assert.AreEqual(4, res.Length);

      Assert.AreEqual("AllwaysOnTop", res[0].OrganizationName);
      Assert.AreEqual("COMPUTERS, HARDWARE", res[1].OrganizationName);
      Assert.AreEqual("4S Consulting, Inc.", res[2].OrganizationName);
      Assert.AreEqual("SmartSolutions", res[3].OrganizationName);

      Assert.AreEqual("Test 1,", res[0].TestField);
      Assert.AreEqual("Test, 2", res[1].TestField);
      Assert.AreEqual(" Test 3", res[2].TestField);
      Assert.AreEqual("Test 4", res[3].TestField);
      
    }

    [Test]
    public void WriteExcelCsv2()
    {
      ArrayList arr = new ArrayList();
      ExcelCsv2Type record;

      record = new ExcelCsv2Type();
      record.OrganizationName = "AllwaysOnTop";
      record.TestField = "Test 1,";
      arr.Add(record);

      record = new ExcelCsv2Type();
      record.OrganizationName = "COMPUTERS, HARDWARE";
      record.TestField = "Test, 2";
      arr.Add(record);

      record = new ExcelCsv2Type();
      record.OrganizationName = "4S Consulting, Inc.";
      record.TestField = " Test 3";
      arr.Add(record);

      record = new ExcelCsv2Type();
      record.OrganizationName = "SmartSolutions";
      record.TestField = "Test 4";
      arr.Add(record);

      engine = new FileHelperEngine(typeof (ExcelCsv2Type));

      string tmp = engine.WriteString(arr.ToArray());
      ExcelCsv2Type[] res = (ExcelCsv2Type[]) engine.ReadString(tmp);
            
      Assert.AreEqual(4, res.Length);

      Assert.AreEqual("AllwaysOnTop", res[0].OrganizationName);
      Assert.AreEqual("COMPUTERS, HARDWARE", res[1].OrganizationName);
      Assert.AreEqual("4S Consulting, Inc.", res[2].OrganizationName);
      Assert.AreEqual("SmartSolutions", res[3].OrganizationName);

      Assert.AreEqual("Test 1,", res[0].TestField);
      Assert.AreEqual("Test, 2", res[1].TestField);
      Assert.AreEqual(" Test 3", res[2].TestField);
      Assert.AreEqual("Test 4", res[3].TestField);
      
    }

    [Test]
    public void ReadExcelCsv3()
    {
      engine = new FileHelperEngine(typeof (ExcelCsv3Type));
      Common.ReadTest(engine, @"Good\ExcelCsv2.txt");
    }

  }

  [DelimitedRecord(",")]
  public sealed class ExcelCsv1Type
  {

    public int Id;
  
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string OrganizationName;

    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string TestField;

  } 

  [DelimitedRecord(",")]
  public sealed class ExcelCsv2Type
  {

    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string OrganizationName;

    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string TestField;

  } 

  [DelimitedRecord(",")]
  public sealed class ExcelCsv3Type
  {

    [FieldQuoted('"')]
    public string OrganizationName;

    [FieldQuoted('"')]
    public string TestField;

  } 
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.