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

namespace FileHelpersTests.CommonTests{
  [TestFixture]
  public class FieldDelimited
  {
    FileHelperEngine engine;

    [Test]
    public void CustomDelimiter()
    {
      engine = new FileHelperEngine(typeof (SOXLog));
      
      SOXLog[] res = (SOXLog[]) Common.ReadTest(engine, @"Good\FieldIgnoredAdvanced.txt");
      Assert.AreEqual(5, res.Length);

      Assert.AreEqual(ActionEnum.Deleted, res[0].ActionType);  
      Assert.AreEqual(ActionEnum.Created, res[2].ActionType);  
      Assert.AreEqual("6/3/2006 5:18:18 AM", res[0].TimeStamp);  
    }


    [DelimitedRecord(" - ")] 
    private class SOXLog 
    { 
      [FieldDelimiter(": ")] 
      internal String DummyField; 
      public ActionEnum ActionType; 
      public String TimeStamp; 
      public String FileName; 
    } 

    /// <summary> 
    /// Enumeration of the types of Actions permitted. 
    /// </summary> 
    private enum ActionEnum 
    { 
      Created, 
      Deleted, 
      Changed 
    } 

    // TEST CLASS
    [DelimitedRecord("|")]
      public class AnotherDelimiterType
    {
      [FieldDelimiter(" - ")]
      public string Street;
      [FieldDelimiter(",")]
      public string Number;
      [FieldTrim(TrimMode.Both)]
      public string City;
      public int Age;
    }

    [Test]
    public void AnotherDelimiterTest()
    {
        engine = new FileHelperEngine(typeof (AnotherDelimiterType));

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

        Assert.AreEqual(4, res.Length);

        Assert.AreEqual("Bahia Blanca", res[0].City);
        Assert.AreEqual("Sin Nombre", res[0].Street);
        Assert.AreEqual("13", res[0].Number);

        Assert.AreEqual("Saavedra", res[1].City);
        Assert.AreEqual("Florencio Sanches", res[1].Street);
        Assert.AreEqual("s/n", res[1].Number);

        Assert.AreEqual("Bs.As", res[2].City);
        Assert.AreEqual("12 de Octubre", res[2].Street);
        Assert.AreEqual("4", res[2].Number);

        Assert.AreEqual("Chilesito", res[3].City);
        Assert.AreEqual("Pololo", res[3].Street);
        Assert.AreEqual("5421", res[3].Number);

      }


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