本文整理汇总了C#中CsvHelper.Tests.Mocks.ParserMock类的典型用法代码示例。如果您正苦于以下问题:C# ParserMock类的具体用法?C# ParserMock怎么用?C# ParserMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParserMock类属于CsvHelper.Tests.Mocks命名空间,在下文中一共展示了ParserMock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetRecordGenericTest
public void GetRecordGenericTest()
{
var parser = new ParserMock
{
{ "Id", "Name" },
{ "a", "b" },
null
};
var reader = new CsvReader( parser );
reader.Read();
try
{
reader.GetRecord<Simple>();
Assert.Fail();
}
catch( CsvTypeConverterException ex )
{
var expected = "Row: '2' (1 based)\r\n" +
"Type: 'CsvHelper.Tests.Exceptions.ExceptionMessageTests+Simple'\r\n" +
"Field Index: '0' (0 based)\r\n" +
"Field Name: 'Id'\r\n" +
"Field Value: 'a'\r\n";
Assert.AreEqual( expected, ex.Data["CsvHelper"] );
}
}
开发者ID:Core2D,项目名称:CsvHelper,代码行数:27,代码来源:ExceptionMessageTests.cs
示例2: ReadTest
public void ReadTest()
{
var queue = new Queue<string[]>();
queue.Enqueue( new[] { "Id", "Names" } );
queue.Enqueue( new[] { "1", "one" } );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var csv = new CsvReader( parserMock );
csv.Read();
var record = csv.GetRecord<Test>();
Assert.IsNull( record.Names );
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:12,代码来源:EnumerableConverterTests.cs
示例3: TryGetDoesNotThrowWhenWillThrowOnMissingFieldIsEnabled
public void TryGetDoesNotThrowWhenWillThrowOnMissingFieldIsEnabled()
{
var data = new[] { "1" };
var queue = new Queue<string[]>();
queue.Enqueue( data );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var reader = new CsvReader( parserMock );
reader.Configuration.WillThrowOnMissingField = true;
reader.Read();
string field;
Assert.IsFalse( reader.TryGetField( "test", out field ) );
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:14,代码来源:TryGetTests.cs
示例4: GetRecordTest
public void GetRecordTest()
{
var data = new List<string[]>
{
new[] { "Id", "Name" },
new[] { "1", "one" },
new[] { "2", "two" },
null
};
var parserMock = new ParserMock( new Queue<string[]>( data ) );
var csvReader = new MyCsvReader( parserMock );
csvReader.GetRecords<Test>().ToList();
}
开发者ID:btebaldi,项目名称:CsvHelper,代码行数:15,代码来源:CsvReaderSubClassingTests.cs
示例5: ReadHeaderDoesNotReadRowTest
public void ReadHeaderDoesNotReadRowTest()
{
var rows = new Queue<string[]>();
rows.Enqueue( new[] { "Id", "Name" } );
rows.Enqueue( new[] { "1", "One" } );
rows.Enqueue( new[] { "2", "two" } );
rows.Enqueue( null );
var parser = new ParserMock( rows );
var csv = new CsvReader( parser );
csv.Read();
csv.ReadHeader();
Assert.IsNull( csv.CurrentRecord );
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:15,代码来源:ReadHeaderTests.cs
示例6: SkipEmptyRowTest
public void SkipEmptyRowTest()
{
var rows = new Queue<string[]>();
rows.Enqueue( new[] { "First,Second" } );
rows.Enqueue( new[] { " " } );
rows.Enqueue( new[] { "1", "2" } );
var parser = new ParserMock( rows );
var csv = new CsvReader( parser );
csv.Configuration.ShouldSkipRecord = row => row.All( string.IsNullOrWhiteSpace );
csv.Read();
Assert.AreEqual( "1", csv.GetField( 0 ) );
Assert.AreEqual( "2", csv.GetField( 1 ) );
}
开发者ID:Core2D,项目名称:CsvHelper,代码行数:15,代码来源:ShouldSkipRecordTests.cs
示例7: ReferenceMappingTest
public void ReferenceMappingTest()
{
var queue = new Queue<string[]>();
queue.Enqueue( new[]
{
"FirstName",
"LastName",
"HomeStreet",
"HomeCity",
"HomeState",
"HomeZip",
"WorkStreet",
"WorkCity",
"WorkState",
"WorkZip"
} );
var row = new[]
{
"John",
"Doe",
"1234 Home St",
"Home Town",
"Home State",
"12345",
"5678 Work Rd",
"Work City",
"Work State",
"67890"
};
queue.Enqueue( row );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var reader = new CsvReader( parserMock );
reader.Read();
var person = reader.GetRecord<Person>();
Assert.AreEqual( "John", person.FirstName );
Assert.AreEqual( "Doe", person.LastName );
Assert.AreEqual( "1234 Home St", person.HomeAddress.Street );
Assert.AreEqual( "Home Town", person.HomeAddress.City );
Assert.AreEqual( "Home State", person.HomeAddress.State );
Assert.AreEqual( "12345", person.HomeAddress.Zip );
Assert.AreEqual( "5678 Work Rd", person.WorkAddress.Street );
Assert.AreEqual( "Work City", person.WorkAddress.City );
Assert.AreEqual( "Work State", person.WorkAddress.State );
Assert.AreEqual( "67890", person.WorkAddress.Zip );
}
开发者ID:sethwebster,项目名称:CsvHelper,代码行数:48,代码来源:ReferenceMappingAttributeTests.cs
示例8: ReadHeaderReadsHeaderTest
public void ReadHeaderReadsHeaderTest()
{
var rows = new Queue<string[]>();
rows.Enqueue( new[] { "Id", "Name" } );
rows.Enqueue( new[] { "1", "One" } );
rows.Enqueue( new[] { "2", "two" } );
rows.Enqueue( null );
var parser = new ParserMock( rows );
var csv = new CsvReader( parser );
csv.Read();
csv.ReadHeader();
Assert.IsNotNull( csv.FieldHeaders );
Assert.AreEqual( "Id", csv.FieldHeaders[0] );
Assert.AreEqual( "Name", csv.FieldHeaders[1] );
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:17,代码来源:ReadHeaderTests.cs
示例9: TryGetFieldInvalidIndexTest
public void TryGetFieldInvalidIndexTest()
{
var data1 = new[] { "One", "Two" };
var data2 = new[] { "one", "two" };
var queue = new Queue<string[]>();
queue.Enqueue( data1 );
queue.Enqueue( data2 );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var reader = new CsvReader( parserMock );
reader.Read();
int field;
var got = reader.TryGetField( 0, out field );
Assert.IsFalse( got );
Assert.AreEqual( default( int ), field );
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:18,代码来源:TryGetTests.cs
示例10: TryGetFieldStrictTest
public void TryGetFieldStrictTest()
{
var data1 = new[] { "One", "Two" };
var data2 = new[] { "1", "2" };
var queue = new Queue<string[]>();
queue.Enqueue( data1 );
queue.Enqueue( data2 );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var reader = new CsvReader( parserMock ) { Configuration = { WillThrowOnMissingField = true } };
reader.Read();
int field;
var got = reader.TryGetField( "One", out field );
Assert.IsTrue( got );
Assert.AreEqual( 1, field );
}
开发者ID:Core2D,项目名称:CsvHelper,代码行数:18,代码来源:TryGetTests.cs
示例11: TryGetFieldTest
public void TryGetFieldTest()
{
var data1 = new[] { "One", "Two" };
var data2 = new[] { "1", "2" };
var queue = new Queue<string[]>();
queue.Enqueue( data1 );
queue.Enqueue( data2 );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var reader = new CsvReader( parserMock );
reader.Read();
int field;
var got = reader.TryGetField( 0, out field );
Assert.IsTrue( got );
Assert.AreEqual( 1, field );
}
开发者ID:Core2D,项目名称:CsvHelper,代码行数:18,代码来源:TryGetTests.cs
示例12: ReadTest
public void ReadTest()
{
var queue = new Queue<string[]>();
queue.Enqueue( new[] { "Names" } );
queue.Enqueue( new[] { "one" } );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var csv = new CsvReader( parserMock );
csv.Read();
try
{
csv.GetRecord<Test>();
Assert.Fail();
}
catch( CsvTypeConverterException )
{
}
}
开发者ID:jhamm,项目名称:CsvHelper,代码行数:18,代码来源:EnumerableConverterTests.cs
示例13: TryGetFieldIndexTest
public void TryGetFieldIndexTest()
{
var parserMock = new ParserMock
{
{ "One", "Two", "Two" },
{ "1", "2", "3" }
};
var reader = new CsvReader( parserMock );
reader.Read();
int field;
var got = reader.TryGetField( "Two", 0, out field );
Assert.IsTrue( got );
Assert.AreEqual( 2, field );
got = reader.TryGetField( "Two", 1, out field );
Assert.IsTrue( got );
Assert.AreEqual( 3, field );
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:19,代码来源:TryGetTests.cs
示例14: ShouldSkipWithEmptyRows
public void ShouldSkipWithEmptyRows()
{
var rows = new Queue<string[]>();
rows.Enqueue( new[] { "First,Second" } );
rows.Enqueue( new[] { "skipme," } );
rows.Enqueue( new[] { "" } );
rows.Enqueue( new[] { "1", "2" } );
var parser = new ParserMock( rows );
var csv = new CsvReader( parser );
csv.Configuration.ShouldSkipRecord = row => row[0].StartsWith( "skipme" );
csv.Configuration.SkipEmptyRecords = true;
csv.Read();
csv.Read();
Assert.AreEqual( "1", csv.GetField( 0 ) );
Assert.AreEqual( "2", csv.GetField( 1 ) );
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:19,代码来源:ShouldSkipRecordTests.cs
示例15: GettingFieldHeadersFailsWhenHeaderNotReadTest
public void GettingFieldHeadersFailsWhenHeaderNotReadTest()
{
var rows = new Queue<string[]>();
rows.Enqueue( new[] { "Id", "Name" } );
rows.Enqueue( new[] { "1", "One" } );
rows.Enqueue( new[] { "2", "two" } );
rows.Enqueue( null );
var parser = new ParserMock( rows );
var csv = new CsvReader( parser );
try
{
var x = csv.FieldHeaders;
Assert.Fail();
}
catch( CsvReaderException )
{
}
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:20,代码来源:ReadHeaderTests.cs
示例16: TryGetFieldEmptyDate
public void TryGetFieldEmptyDate()
{
// DateTimeConverter.IsValid() doesn't work correctly
// so we need to test and make sure that the conversion
// fails for an emptry string for a date.
var data = new[] { " " };
var queue = new Queue<string[]>();
queue.Enqueue( data );
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var reader = new CsvReader( parserMock );
reader.Configuration.HasHeaderRecord = false;
reader.Read();
DateTime field;
var got = reader.TryGetField( 0, out field );
Assert.IsFalse( got );
Assert.AreEqual( DateTime.MinValue, field );
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:21,代码来源:TryGetTests.cs
示例17: GetMissingFieldTest
public void GetMissingFieldTest()
{
var parser = new ParserMock
{
{ "Id", "Name" },
{ "a", "b" },
null
};
var reader = new CsvReader( parser );
reader.Read();
reader.Read();
try
{
reader.GetField( 2 );
Assert.Fail();
}
catch( CsvMissingFieldException ex )
{
Assert.AreEqual( 2, ex.Row );
Assert.AreEqual( 2, ex.FieldIndex );
}
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:23,代码来源:ExceptionMessageTests.cs
示例18: GetMissingFieldTest
public void GetMissingFieldTest()
{
var parser = new ParserMock
{
{ "Id", "Name" },
{ "a", "b" },
null
};
var reader = new CsvReader( parser );
reader.Read();
try
{
reader.GetField( 2 );
Assert.Fail();
}
catch( CsvMissingFieldException ex )
{
var expected = "Row: '2' (1 based)\r\n" +
"Type: 'System.String'\r\n" +
"Field Index: '2' (0 based)\r\n";
Assert.AreEqual( expected, ex.Data["CsvHelper"] );
}
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:24,代码来源:ExceptionMessageTests.cs
示例19: GetGenericMissingFieldWithTypeTest
public void GetGenericMissingFieldWithTypeTest()
{
var parser = new ParserMock
{
{ "Id", "Name" },
{ "a", "b" },
null
};
var reader = new CsvReader( parser );
reader.Read();
reader.Read();
try
{
reader.GetField<int>( 2 );
Assert.Fail();
}
catch( CsvMissingFieldException ex )
{
Assert.AreEqual( 2, ex.Row );
Assert.AreEqual( ex.Type, typeof( int ) );
Assert.AreEqual( 2, ex.FieldIndex );
}
}
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:24,代码来源:ExceptionMessageTests.cs
示例20: GetRecordEmptyFileWithHeaderOnTest
public void GetRecordEmptyFileWithHeaderOnTest()
{
var queue = new Queue<string[]>();
queue.Enqueue( null );
var parserMock = new ParserMock( queue );
var csvReader = new CsvReader( parserMock );
try
{
csvReader.Read();
Assert.Fail();
}
catch( CsvReaderException )
{
}
}
开发者ID:Orcomp,项目名称:CsvHelper,代码行数:16,代码来源:CsvReaderTests.cs
注:本文中的CsvHelper.Tests.Mocks.ParserMock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论