public void TestGetSchema_NotExtracted_Throws() { string text = "a,b,c"; SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = false }; IParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), options); parser.GetSchema(); }
public void TestGetSchema_Extracted_ReturnsColumnNames() { string text = "a,b,c"; SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = true }; IParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), options); Schema schema = parser.GetSchema(); Assert.IsTrue(schema.ColumnDefinitions.All(d => d is StringColumn), "Not all of the columns were treated as strings."); string[] actual = schema.ColumnDefinitions.Select(d => d.ColumnName).ToArray(); string[] expected = new string[] { "a", "b", "c" }; CollectionAssert.AreEqual(expected, actual, "The schema was not extracted as expected."); }
public void TestGetSchema_SchemaProvided_FirstRecordSchema_SkipsFirstRecord() { const string text = @"id,name,created"; Schema schema = new Schema(); schema.AddColumn(new Int32Column("id")) .AddColumn(new StringColumn("name")) .AddColumn(new DateTimeColumn("created")); SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = true }; IParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options); Schema actual = parser.GetSchema(); Assert.AreSame(schema, actual, "The schema was passed did not take priority."); Assert.IsFalse(parser.Read(), "The schema record was not skipped."); }
public void TestGetSchema_SchemaProvided_FirstRecordSchema_SkipsFirstRecord() { const string text = @"id,name,created"; Schema schema = new Schema(); schema.AddColumn(new Int32Column("id")) .AddColumn(new StringColumn("name")) .AddColumn(new DateTimeColumn("created")); SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = true }; IParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema, options); Schema actual = parser.GetSchema(); Assert.AreSame(schema, actual, "The schema was passed did not take priority."); Assert.IsFalse(parser.Read(), "The schema record was not skipped."); }
public void TestGetSchema_NotExtracted_Throws() { string text = "a,b,c"; SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = false }; IParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), options); parser.GetSchema(); }
public void TestGetSchema_Extracted_ReturnsColumnNames() { string text = "a,b,c"; SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = true }; IParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), options); Schema schema = parser.GetSchema(); Assert.IsTrue(schema.ColumnDefinitions.All(d => d is StringColumn), "Not all of the columns were treated as strings."); string[] actual = schema.ColumnDefinitions.Select(d => d.ColumnName).ToArray(); string[] expected = new string[] { "a", "b", "c" }; CollectionAssert.AreEqual(expected, actual, "The schema was not extracted as expected."); }