public void TestRead_ValuesAfterEndOfFile_Throws() { string text = "a,b,c"; SeparatedValueParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text))); bool canRead = parser.Read(); Assert.IsTrue(canRead, "Could not read the record."); canRead = parser.Read(); Assert.IsFalse(canRead, "We should have reached the end of the file."); parser.GetValues(); }
public void TestRead_SingleRecord_ReturnsTrueOnce() { const string text = "a,b,c"; SeparatedValueParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text))); bool canRead = parser.Read(); Assert.IsTrue(canRead, "Could not read the record."); string[] expected = new string[] { "a", "b", "c" }; object[] actual = parser.GetValues(); CollectionAssert.AreEqual(expected, actual, "The wrong values were parsed."); canRead = parser.Read(); Assert.IsFalse(canRead, "No more records should have been read."); }
public void TestGetSchema_FirstRecordSchema_WrongNumberOfColumns_Throws() { const string text = @"id,name,created 123,Bob,1/19/2013,Hello"; SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = true }; SeparatedValueParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), options); parser.Read(); }
public void TestGetSchema_SchemaProvided_WrongNumberOfColumns_Throws() { const string text = @"123,Bob"; Schema schema = new Schema(); schema.AddColumn(new Int32Column("id")) .AddColumn(new StringColumn("name")) .AddColumn(new DateTimeColumn("created")); SeparatedValueParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema); parser.Read(); }
public void TestRead_MultipleCallsToValues_ReturnsSameValues() { string text = "a,b,c"; SeparatedValueParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text))); bool canRead = parser.Read(); Assert.IsTrue(canRead, "Could not read the record."); string[] expected = new string[] { "a", "b", "c" }; object[] actual = parser.GetValues(); CollectionAssert.AreEqual(expected, actual, "The wrong values were parsed."); actual = parser.GetValues(); CollectionAssert.AreEqual(expected, actual, "The same values were not returned multiple times."); }
public void TestGetSchema_SchemaProvided_ParsesValues() { const string text = @"123,Bob,1/19/2013"; Schema schema = new Schema(); schema.AddColumn(new Int32Column("id")) .AddColumn(new StringColumn("name")) .AddColumn(new DateTimeColumn("created")); SeparatedValueParser parser = new SeparatedValueParser(new MemoryStream(Encoding.Default.GetBytes(text)), schema); Assert.IsTrue(parser.Read(), "The first record was skipped."); object[] actual = parser.GetValues(); object[] expected = new object[] { 123, "Bob", new DateTime(2013, 1, 19) }; CollectionAssert.AreEqual(expected, actual, "The values were not parsed 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."); }