BadUsage.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpersTests » Errors » 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 » Errors » BadUsage.cs
using System;
using System.IO;
using System.Reflection;
using FileHelpers;
using NUnit.Framework;

namespace FileHelpersTests.Errors{
  [TestFixture]
  public class BadUsage
  {
    #region  "  DuplicateAttributes  "

    [FixedLengthRecord]
    public class TestDupli
    {
      [FieldFixedLength(10)]
      [FieldDelimiter("|")] public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void DuplicatedDefinition()
    {
      new FileHelperEngine(typeof (TestDupli));
    }

    #endregion

    #region  "  SwitchedAttributes "

    [FixedLengthRecord]
    public class SwitchedAttributes1
    {
      [FieldDelimiter("|")] public string Field1;
    }

    [DelimitedRecord("|")]
    public class SwitchedAttributes2
    {
      [FieldFixedLength(12)] public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void SwitchedAttb1()
    {
      new FileHelperEngine(typeof (SwitchedAttributes1));
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void SwitchedAttb2()
    {
      new FileHelperEngine(typeof (SwitchedAttributes2));
    }

    #endregion

    #region  "  NullValue "

    [DelimitedRecord("|")]
    public class NullValue1Type
    {
      [FieldNullValue(22)] public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NullValue1()
    {
      new FileHelperEngine(typeof (NullValue1Type));
    }

    #endregion

    #region  "  NoMarkedClass "

    public class NoMarkedClass
    {
      [FieldNullValue(22)] public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoMarked()
    {
      new FileHelperEngine(typeof (NoMarkedClass));
    }

    #endregion

    #region  "  FixedWithOutLength "

    [FixedLengthRecord]
    public class FixedWithOutLengthClass
    {
      public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void FixedWithOutLength()
    {
      new FileHelperEngine(typeof (FixedWithOutLengthClass)); ;
    }

    #endregion

    #region  "  NoFields "

    [FixedLengthRecord]
    public class NoFieldsClass
    {
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoFields()
    {
      new FileHelperEngine(typeof (NoFieldsClass));
    }

    #endregion

    #region  "  NoFields2"

    [DelimitedRecord(",")]
    public class NoFieldsClass2
    {
      [FieldIgnored]
      public string MyField;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoFields2()
    {
      new FileHelperEngine(typeof (NoFieldsClass2));
    }

    #endregion

    #region  "  NoFields3  "

    [DelimitedRecord(",")]
      public class NoFieldsClass3
    {
      [FieldIgnored]
      public string MyField;

      [FieldIgnored]
      public string MyField2;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoFields3()
    {
      new FileHelperEngine(typeof (NoFieldsClass3));
    }

    #endregion


    #region  "  NoConstructor  "

    [FixedLengthRecord]
    public class NoConstructorClass
    {
      [FieldFixedLength(22)] public string Field1;

      public NoConstructorClass(bool foo)
      {
        foo = true;
      }
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoConstructor()
    {
      new FileHelperEngine(typeof (NoConstructorClass));
    }

    #endregion


    #region  "  NoConstructorConverter  "

    private class ConvClass: ConverterBase
    {
      public ConvClass(bool foo)
      {}

      public override object StringToField(string from)
      {
        throw new NotImplementedException();
      }
    }


    [DelimitedRecord(",")]
    public class NoConstructorConvClass
    {
      [FieldConverter(typeof(ConvClass))]
      public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoConstructorConverter()
    {
      new FileHelperEngine(typeof (NoConstructorConvClass));
    }


    [DelimitedRecord(",")]
    public class NoConstructorConvClass2
    {
      [FieldConverter(typeof(ConvClass), "hola")]
      public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoConstructorConverter2()
    {
      new FileHelperEngine(typeof (NoConstructorConvClass2));
    }


    [DelimitedRecord(",")]
    public class NoConstructorConvClass3
    {
      [FieldConverter(typeof(ConvClass), 123)]
      public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoConstructorConverter3()
    {
      new FileHelperEngine(typeof (NoConstructorConvClass3));
    }

    [DelimitedRecord(",")]
    public class NoConstructorConvClass4
    {
      [FieldConverter(typeof(FakeConverter), 123)]
      public string Field1;

      private class FakeConverter
      {}

    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NoConstructorConverter4()
    {
      new FileHelperEngine(typeof (NoConstructorConvClass4));
    }

    #endregion

    #region  "  DateFormat  "

    [DelimitedRecord("|")]
    public class DateFormat1Class
    {
      [FieldConverter(ConverterKind.Date, null)] public DateTime DateField;
    }

    [DelimitedRecord("|")]
    public class DateFormat2Class
    {
      [FieldConverter(ConverterKind.Date, "")] public DateTime DateField;
    }

    [DelimitedRecord("|")]
    public class DateFormat3Class
    {
      [FieldConverter(ConverterKind.Date, "d#|||??3&&...dddMMyyyy")] public DateTime DateField;
    }


    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void BadDateFormat1()
    {
      new FileHelperEngine(typeof (DateFormat1Class));
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void BadDateFormat2()
    {
      new FileHelperEngine(typeof (DateFormat2Class));
    }

//    [Test]
//    [ExpectedException(typeof (BadUsageException))]
//    public void BadDateFormat3()
//    {
//      new FileHelperEngine(typeof (DateFormat3Class));
//    }

    #endregion

//    #region  "  TrimBad  "
//
//    [DelimitedRecord("|")]
//    public class TrimClass
//    {
//      [Trim(TrimMode.Both)]
//      public int Field1;
//    }
//
//    [Test]
//    [ExpectedException(typeof (BadUsageException))]
//    public void TrimOtherThanString()
//    {
//      new FileHelperEngine(typeof (TrimClass));
//    }
//
//    #endregion

    #region  "  AlignBad  "

    [DelimitedRecord("|")]
    public class AlignClass
    {
      [FieldAlign(AlignMode.Left)] public int Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void AlignError()
    {
      new FileHelperEngine(typeof (AlignClass));
    }

    #endregion

    #region  "  NonSystemType  "

    [DelimitedRecord("|")]
    public class NonSystemTypeClass
    {
      // One non system type ex FileInfo
      public FileInfo Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NonSystemType()
    {
      new FileHelperEngine(typeof (NonSystemTypeClass));
    }

    #endregion

    #region  "  ValueType  "

    public struct ValueTypeClass
    {
      // One non system type ex FileInfo
      public FileInfo Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void ValueType()
    {
      new FileHelperEngine(typeof (ValueTypeClass));
    }

    #endregion


    #region  "  BadRecordTypes  "

    [DelimitedRecord("|")]
    public class BadRecordTypeClass
    {
      public string Field1;
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void BadRecordType()
    {
      FileHelperEngine engine = new FileHelperEngine(typeof (BadRecordTypeClass));
      string res = engine.WriteString(new string[] {"hola"});
      Console.Write(res);
    }

    [Test]
    [ExpectedException(typeof (BadUsageException))]
    public void NullRecordType()
    {
      new FileHelperEngine(null);
    }

    #endregion

    [Test]
    [ExpectedException(typeof(BadUsageException))]
    public void WriteBadUsage()
    {
      FileHelperEngine engine = new FileHelperEngine(typeof (SampleType));

      SampleType[] res = new SampleType[2];

      res[0] = new SampleType();

      res[0].Field1 = DateTime.Now.AddDays(1);
      res[0].Field2 = "je";
      res[0].Field3 = 0;

      engine.WriteString(res);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void WriteBadUsage2()
    {
      FileHelperEngine engine = new FileHelperEngine(typeof (SampleType));
      engine.WriteString(null);
    }


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