private static void RunStringFixedReader() { string path = @"C:\path\to\some_file.csv"; List<FixedFieldFormat> formats = new List<FixedFieldFormat> { new FixedFieldFormat(0, 5), new FixedFieldFormat(5, 3), new FixedFieldFormat(8, 4), new FixedFieldFormat(12, 2) }; List<string[]> records; using (TextReader textReader = new StreamReader(path)) { StringFixedReader reader = new StringFixedReader(textReader, formats); records = reader.ReadToEnd(); } }
private static void RunStringFixedReader() { string path = @"C:\path\to\some_file.csv"; List <FixedFieldFormat> formats = new List <FixedFieldFormat> { new FixedFieldFormat(0, 5), new FixedFieldFormat(5, 3), new FixedFieldFormat(8, 4), new FixedFieldFormat(12, 2) }; List <string[]> records; using (TextReader textReader = new StreamReader(path)) { StringFixedReader reader = new StringFixedReader(textReader, formats); records = reader.ReadToEnd(); } }
public void TestReadToEnd() { List <FixedFieldFormat> formats = new List <FixedFieldFormat> { new FixedFieldFormat(0, 5), new FixedFieldFormat(5, 3) }; string content = "abcde123\nhijkl456\nstuvw789"; string[] expectedFirst = new string[] { "abcde", "123" }; string[] expectedSecond = new string[] { "hijkl", "456" }; string[] expectedThird = new string[] { "stuvw", "789" }; int expectedLength = 3; using (StringReader textReader = new StringReader(content)) { StringFixedReader reader = new StringFixedReader(textReader, formats); 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); } }
public void TestReadToEnd() { List<FixedFieldFormat> formats = new List<FixedFieldFormat> { new FixedFieldFormat(0, 5), new FixedFieldFormat(5, 3) }; string content = "abcde123\nhijkl456\nstuvw789"; string[] expectedFirst = new string[] { "abcde", "123" }; string[] expectedSecond = new string[] { "hijkl", "456" }; string[] expectedThird = new string[] { "stuvw", "789" }; int expectedLength = 3; using (StringReader textReader = new StringReader(content)) { StringFixedReader reader = new StringFixedReader(textReader, formats); 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); } }