public void Test_CSV_HeadingBeyondData( ) { string csv = "\n1,2\nA,B"; var service = new CsvFileReaderService( ); var settings = new DataFileReaderSettings( ); settings.FirstDataRowNumber = 2; settings.HeadingRowNumber = 3; SampleDataCreator creator = new SampleDataCreator( ); using (Stream stream = SheetTestHelper.GetCsvStream(csv)) { SampleTable table = creator.CreateSample(stream, settings, service); Assert.That(table, Is.Not.Null); Assert.That(table.Columns, Has.Count.EqualTo(2)); Assert.That(table.Rows, Has.Count.EqualTo(0)); SampleColumn column = table.Columns [0]; Assert.That(column.ColumnName, Is.EqualTo("1")); Assert.That(column.Name, Is.EqualTo("A")); column = table.Columns [1]; Assert.That(column.ColumnName, Is.EqualTo("2")); Assert.That(column.Name, Is.EqualTo("B")); } }
public void Test_CSV( ) { string csv = "TestString,TestNumber\nA,1\nB,2\nC,3\nD,4\nE,5\nA,1\nB,2\nC,3\nD,4\nE,5\n,A,1\nB,2\nC,3\nD,4\nE,5\n"; var service = new CsvFileReaderService( ); var settings = new DataFileReaderSettings( ); SampleDataCreator creator = new SampleDataCreator( ); using (Stream stream = SheetTestHelper.GetCsvStream(csv)) { SampleTable table = creator.CreateSample(stream, settings, service); Assert.That(table, Is.Not.Null); Assert.That(table.Columns, Has.Count.EqualTo(2)); Assert.That(table.Rows, Has.Count.EqualTo(10)); SampleColumn column = table.Columns[0]; Assert.That(column.ColumnName, Is.EqualTo("1")); Assert.That(column.Name, Is.EqualTo("TestString")); column = table.Columns[1]; Assert.That(column.ColumnName, Is.EqualTo("2")); Assert.That(column.Name, Is.EqualTo("TestNumber")); SampleRow row = table.Rows[0]; Assert.That(row.Values, Has.Count.EqualTo(2)); Assert.That(row.Values[0], Is.EqualTo("A")); Assert.That(row.Values[1], Is.EqualTo("1")); row = table.Rows[9]; Assert.That(row.Values, Has.Count.EqualTo(2)); Assert.That(row.Values[0], Is.EqualTo("E")); Assert.That(row.Values[1], Is.EqualTo("5")); } }
public void Test_CSV_NoData( ) { string csv = ""; var service = new CsvFileReaderService( ); var settings = new DataFileReaderSettings( ); SampleDataCreator creator = new SampleDataCreator( ); using (Stream stream = SheetTestHelper.GetCsvStream(csv)) { SampleTable table = creator.CreateSample(stream, settings, service); Assert.That(table, Is.Not.Null); Assert.That(table.Columns, Has.Count.EqualTo(0)); Assert.That(table.Rows, Has.Count.EqualTo(0)); } }
private List <IObjectReader> TestRecords(string csv, DataFileReaderSettings settings, int expectedCount) { var service = GetService( ); List <IObjectReader> objects; using (Stream stream = SheetTestHelper.GetCsvStream(csv)) using (IObjectsReader objectsReader = service.OpenDataFile(stream, settings ?? new DataFileReaderSettings { ImportFormat = ImportFormat.Tab })) { objects = objectsReader.GetObjects( ).ToList( ); } Assert.That(objects, Is.Not.Null, "objects"); Assert.That(objects.Count, Is.EqualTo(expectedCount)); return(objects); }