public void TestReadToEnd() { string delimiter = ","; string content = "a,b\nc,d\ne,f"; string[] expectedFirst = new string[] { "a", "b" }; string[] expectedSecond = new string[] { "c", "d" }; string[] expectedThird = new string[] { "e", "f" }; int expectedLength = 3; using (StringReader textReader = new StringReader(content)) { StringDelimitedReader reader = new StringDelimitedReader(textReader, delimiter); List<string[]> records = reader.ReadToEnd(); Assert.AreEqual(expectedLength, records.Count); string[] actualFirst = records[0]; Assert.IsNotNull(actualFirst); CollectionAssert.AreEqual(expectedFirst, actualFirst); string[] actualSecond = records[1]; Assert.IsNotNull(actualSecond); CollectionAssert.AreEqual(expectedSecond, actualSecond); string[] actualThird = records[2]; Assert.IsNotNull(actualThird); CollectionAssert.AreEqual(expectedThird, actualThird); } }
private static void RunStringDelimitedReader() { string path = @"C:\path\to\some_file.csv"; string delimiter = ","; List<string[]> records; using (TextReader textReader = new StreamReader(path)) { StringDelimitedReader reader = new StringDelimitedReader(textReader, delimiter); records = reader.ReadToEnd(); } }