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

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

    [Test]
    public void DiscardLast1()
    {
      engine = new FileHelperEngine(typeof (DiscardLastType0));

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

      Assert.AreEqual(4, res.Length);
      Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
    }

    [Test]
    public void DiscardLast2()
    {
      engine = new FileHelperEngine(typeof (DiscardLastType1));

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

            Assert.AreEqual(engine.TotalRecords, res.Length);

      Assert.AreEqual(4, res.Length);
      Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
    }

        [Test]
        public void DiscardLast2bis()
        {
            engine = new FileHelperEngine(typeof(DiscardLastType1bis));

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

            Assert.AreEqual(engine.TotalRecords, res.Length);

            Assert.AreEqual(3, res.Length);
            Assert.AreEqual(new DateTime(1314, 11, 10), res[0].Field1);
        }

        [Test]
    public void DiscardLast3()
    {
      engine = new FileHelperEngine(typeof (DiscardLastType11));

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

      Assert.AreEqual(4, res.Length);
      Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
    }

    [Test]
    public void DiscardLast4()
    {
      engine = new FileHelperEngine(typeof (DiscardLastType2));

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

      Assert.AreEqual(4, res.Length);
      Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
      Assert.AreEqual("you can get this lines\r\nwith the FileHelperEngine.FooterText property\r\n", engine.FooterText);
    }

    [Test]
    public void DiscardLast5()
    {
      engine = new FileHelperEngine(typeof (DiscardLastType2));

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

      Assert.AreEqual(4, res.Length);
      Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
    }

    [Test]
    public void DiscardLast6()
    {
      asyncEngine = new FileHelperAsyncEngine(typeof (DiscardLastType2));

      Common.BeginReadTest(asyncEngine, @"Good\DiscardLast2.txt");

            ArrayList arr = new ArrayList();
            while (asyncEngine.ReadNext() != null)
            {
                arr.Add(asyncEngine.LastRecord);
            }

            Assert.AreEqual(4, asyncEngine.TotalRecords);
            
      Assert.AreEqual("you can get this lines\r\nwith the FileHelperEngine.FooterText property\r\n", asyncEngine.FooterText);

            Assert.AreEqual(new DateTime(1314, 12, 11), ((DiscardLastType2)arr[0]).Field1);

    }


    [Test]
    public void DiscardWriteRead()
    {
      engine = new FileHelperEngine(typeof (DiscardLastType1));

      DiscardLastType1[] res = (DiscardLastType1[]) Common.ReadTest(engine, @"Good\DiscardLast1.txt");
      engine.FooterText = "This is a new Footer....\r\n";

      engine.WriteFile("tempo.txt", res);
      
            engine.FooterText = "none none";

      DiscardLastType1[] res2 = (DiscardLastType1[]) engine.ReadFile(@"tempo.txt");

      Assert.AreEqual(res.Length, res2.Length);
      Assert.AreEqual("This is a new Footer....\r\n", engine.FooterText);

      if (File.Exists("tempo.txt")) File.Delete("tempo.txt");

      Assert.AreEqual(4, res.Length);
      Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1);
    }

        [Test]
        public void DiscardWriteRead2()
        {
            engine = new FileHelperEngine(typeof(DiscardLastType1));

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


            asyncEngine = new FileHelperAsyncEngine(typeof(DiscardLastType1));

            asyncEngine.FooterText = "This is a new Footer....";

            asyncEngine.BeginWriteFile("temp.txt");
            asyncEngine.WriteNexts(res);
            asyncEngine.Close();

            asyncEngine.FooterText = "none none";

            asyncEngine.BeginReadFile("temp.txt");

            while (asyncEngine.ReadNext() != null)
            {}

            Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
            Assert.AreEqual("This is a new Footer....\r\n", asyncEngine.FooterText);

            asyncEngine.Close();

            Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
            Assert.AreEqual("This is a new Footer....\r\n", asyncEngine.FooterText);

            if (File.Exists("tempo.txt")) File.Delete("tempo.txt");
        }



  }

  [FixedLengthRecord]
  [IgnoreLast(0)]
    [IgnoreFirst(0)]
    public class DiscardLastType0
  {
    [FieldFixedLength(8)]
    [FieldConverter(ConverterKind.Date, "ddMMyyyy")] public DateTime Field1;

    [FieldFixedLength(3)] public string Field2;

    [FieldFixedLength(3)]
    [FieldConverter(ConverterKind.Int32)] public int Field3;

  }

  [FixedLengthRecord]
    [IgnoreLast()]
  public class DiscardLastType1
  {
    [FieldFixedLength(8)]
    [FieldConverter(ConverterKind.Date, "ddMMyyyy")] public DateTime Field1;

    [FieldFixedLength(3)] public string Field2;

    [FieldFixedLength(3)]
    [FieldConverter(ConverterKind.Int32)] public int Field3;

  }

    [FixedLengthRecord]
    [IgnoreFirst()]
    [IgnoreLast()]
    public class DiscardLastType1bis
    {
        [FieldFixedLength(8)]
        [FieldConverter(ConverterKind.Date, "ddMMyyyy")]
        public DateTime Field1;

        [FieldFixedLength(3)]
        public string Field2;

        [FieldFixedLength(3)]
        [FieldConverter(ConverterKind.Int32)]
        public int Field3;

    }

  [FixedLengthRecord]
  [IgnoreLast(1)]
  public class DiscardLastType11
  {
    [FieldFixedLength(8)]
    [FieldConverter(ConverterKind.Date, "ddMMyyyy")] public DateTime Field1;

    [FieldFixedLength(3)] public string Field2;

    [FieldFixedLength(3)]
    [FieldConverter(ConverterKind.Int32)] public int Field3;

  }

  [FixedLengthRecord]
  [IgnoreLast(2)]
  public class DiscardLastType2
  {
    [FieldFixedLength(8)]
    [FieldConverter(ConverterKind.Date, "ddMMyyyy")] public DateTime Field1;

    [FieldFixedLength(3)] public string Field2;

    [FieldFixedLength(3)]
    [FieldConverter(ConverterKind.Int32)] public int Field3;

  }

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