Encoding.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 » Encoding.cs
using System;
using System.Collections;
using System.Text;
using FileHelpers;
using NUnit.Framework;

namespace FileHelpersTests.CommonTests{
  [TestFixture]
  public class FileEncoding
  {
    FileHelperEngine engine;
    FileHelperAsyncEngine asyncEngine;

    private const int ExpectedRecords = 7;

    private void RunTests(string fileName, Encoding enc)
    {
      engine = new FileHelperEngine(typeof (CustomersVerticalBar));
      engine.Encoding = enc;
      Assert.AreEqual(enc, engine.Encoding);
      CoreRunTest(fileName);
    }

    private void RunConstructor(string fileName, Encoding enc)
    {
      engine = new FileHelperEngine(typeof (CustomersVerticalBar), enc);
      Assert.AreEqual(enc, engine.Encoding);
      CoreRunTest(fileName);
    }

    private void CoreRunTest(string fileName)
    {
  
      CustomersVerticalBar[] res = (CustomersVerticalBar[]) Common.ReadTest(engine, fileName);
  
      Assert.AreEqual(ExpectedRecords, res.Length);
      Assert.AreEqual(ExpectedRecords, engine.TotalRecords);
  
      Assert.AreEqual("Ana Truio Emparedados y helados", res[1].CompanyName);
      Assert.AreEqual("Blondesddsl pre et fils", res[6].CompanyName);
      Assert.AreEqual("Frdrique Citeaux", res[6].ContactName);
  
      Assert.AreEqual("24, place Klber", res[6].Address);
      Assert.AreEqual("Berguvsvgen  8", res[4].Address);
      Assert.AreEqual("Lule", res[4].City);
    }

    private void RunAsyncTests(string fileName, Encoding enc)
    {
      asyncEngine = new FileHelperAsyncEngine(typeof (CustomersVerticalBar));
      asyncEngine.Encoding = enc;
      Assert.AreEqual(enc, asyncEngine.Encoding);

      CoreRunAsync(fileName);
    }

    private void RunAsyncConstructor(string fileName, Encoding enc)
    {
      asyncEngine = new FileHelperAsyncEngine(typeof (CustomersVerticalBar), enc);
      Assert.AreEqual(enc, asyncEngine.Encoding);

      CoreRunAsync(fileName);
    }

    private void CoreRunAsync(string fileName)
    {
      ArrayList arr = new ArrayList();
  
      Common.BeginReadTest(asyncEngine, fileName);

      foreach (object record in asyncEngine)
      {
        arr.Add(record);
      }
  
      CustomersVerticalBar[] res = (CustomersVerticalBar[]) arr.ToArray(typeof (CustomersVerticalBar));
      Assert.AreEqual(ExpectedRecords, res.Length);
      Assert.AreEqual(ExpectedRecords, engine.TotalRecords);
  
      Assert.AreEqual("Ana Truio Emparedados y helados", res[1].CompanyName);
      Assert.AreEqual("Blondesddsl pre et fils", res[6].CompanyName);
      Assert.AreEqual("Frdrique Citeaux", res[6].ContactName);
  
      Assert.AreEqual("24, place Klber", res[6].Address);
      Assert.AreEqual("Berguvsvgen  8", res[4].Address);
      Assert.AreEqual("Lule", res[4].City);
    }

    [Test]
    public void EncodingANSI()
    {
      RunTests(@"Good\EncodingANSI.txt", Encoding.Default);
    }

    [Test]
    public void EncodingUTF8()
    {
      RunTests(@"Good\EncodingUTF8.txt", Encoding.UTF8);
    }

    [Test]
    public void EncodingUnicode()
    {
      RunTests(@"Good\EncodingUnicode.txt", Encoding.Unicode);
    }

    [Test]
    public void EncodingAsyncUnicodeBig()
    {
      RunAsyncTests(@"Good\EncodingUnicodeBig.txt", Encoding.BigEndianUnicode);
    }

    [Test]
    public void EncodingAsyncANSI()
    {
      RunAsyncTests(@"Good\EncodingANSI.txt", Encoding.Default);
    }

    [Test]
    public void EncodingAsyncUTF8()
    {
      RunAsyncTests(@"Good\EncodingUTF8.txt", Encoding.UTF8);
    }

    [Test]
    public void EncodingAsyncUnicode()
    {
      RunAsyncTests(@"Good\EncodingUnicode.txt", Encoding.Unicode);
    }

    [Test]
    public void EncodingUnicodeBig()
    {
      RunTests(@"Good\EncodingUnicodeBig.txt", Encoding.BigEndianUnicode);
    }


    [Test]
    public void EncodingAsyncANSIConstructor()
    {
      RunConstructor(@"Good\EncodingANSI.txt", Encoding.Default);
    }

    [Test]
    public void EncodingAsyncUTFConstructor()
    {
      RunConstructor(@"Good\EncodingUTF8.txt", Encoding.UTF8);
    }

    [Test]
    public void EncodingAsyncUnicodeConstructor()
    {
      RunConstructor(@"Good\EncodingUnicode.txt", Encoding.Unicode);
    }

    [Test]
    public void EncodingANSIConstructorAsync()
    {
      RunAsyncConstructor(@"Good\EncodingANSI.txt", Encoding.Default);
    }

    [Test]
    public void EncodingUTF8ConstructorAsync()
    {
      RunAsyncConstructor(@"Good\EncodingUTF8.txt", Encoding.UTF8);
    }

    [Test]
    public void EncodingUnicodeConstructorAsync()
    {
      RunAsyncConstructor(@"Good\EncodingUnicode.txt", Encoding.Unicode);
    }

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