public void ReadSingleDataRow() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("1,2,3"); DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n"); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "2", "3" }); }
public void ReadColumnNamesTest() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("A,B,C\r\n1,2,3"); DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n"); parser.ColumnNameInFirstRow = true; parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "A", "B", "C" }); }
public void ParseSingleQualifiedColumn() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("\"A,B\r\n\",C\r\n1,2,3"); RowParser rowParser = new RowParser(string.Empty, "\r\n", "\""); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, "\"A,B\r\n\",C\r\n", new string[] { "A,B\r\n,C" }); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, "1,2,3", new string[] { "1,2,3" }); }
public void ParseSimpleRows() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("A,B,C\r\n1,2,3"); RowParser rowParser = new RowParser(",", "\r\n", string.Empty); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, "A,B,C\r\n", new string[] { "A", "B", "C" }); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, "1,2,3", new string[] { "1", "2", "3" }); }
public void ParseRowsWithUnevenFields() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("A,B,C,D\r\n1,2,3"); RowParser rowParser = new RowParser(",", "\r\n", "\""); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "A", "B", "C", "D" }); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "2", "3" }); }
public void ParseQualifiedRowsWithError() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("A,\"B\" \r\n1,2,3"); RowParser rowParser = new RowParser(",", "\r\n", "\""); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "A", "B " }); rowParser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "2", "3" }); }
public void ReadSingleColumnRows2() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("ABC\r\nDEF\r\nGHI"); DelimitedFileParser parser = new DelimitedFileParser(string.Empty, "\r\n"); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "ABC" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "DEF" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "GHI" }); }
public void ReadSingleColumnRows() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("1,2,3"); DelimitedFileParser parser = new DelimitedFileParser(string.Empty, ","); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "1" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "2" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "3" }); }
public void ReadColumnNamesAfterHeaderTest() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader text\r\nA,B,C\r\n1,2,3"); DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n"); parser.ColumnNameInFirstRow = true; parser.HeaderRowDelimiter = "\r\n"; parser.HeaderRowsToSkip = 3; parser.SkipHeaderRows(reader); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "A", "B", "C" }); }
public void ReadMultipleDataRows() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("1,1,1,1\r\n2,2,2,2\r\n3,3,3,3\r\n4,4,4,4"); DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n"); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "1", "1", "1" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "2", "2", "2", "2" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "3", "3", "3", "3" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "4", "4", "4", "4" }); }
public void ReadSingleColumnRows3() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("\"ABC\"\r\n\"DE\"F\r\n\"G\"HI"); DelimitedFileParser parser = new DelimitedFileParser(string.Empty, "\r\n"); parser.TextQualifier = "\""; parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "ABC" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "DEF" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "GHI" }); }
public void ReadMultipleDataRowsAfterHeaderWithMessyParsing() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader text\r\n A)::-)brr\"-:-)\r\n-\r\nasdfghj\"-\"\"-\":-)\"-\":-)\"-\"\"-\"\"-\":--\r"); DelimitedFileParser parser = new DelimitedFileParser(":-)", "-\r\n"); parser.HeaderRowDelimiter = "\r\n"; parser.HeaderRowsToSkip = 3; parser.TextQualifier = "\"-\""; parser.SkipHeaderRows(reader); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { " A):", "brr\"-", "\r\n" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "asdfghj\"-\"\"-\"", ":-)\"-\":-" }); }
public void TestSkippingRows() { RowData rowData = new RowData(); IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader\r\nA,B,C,D\r\n1,1,1,1\r\n2,2,2,2\r\n3,3,3,3\r\n4,4,4,4\r\n"); DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n"); parser.HeaderRowDelimiter = "\r\n"; parser.HeaderRowsToSkip = 3; parser.DataRowsToSkip = 3; parser.ColumnNameInFirstRow = true; parser.SkipInitialRows(reader); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[] { "4", "4", "4", "4" }); parser.ParseNextRow(reader, rowData); RowDataTest.VerifyParsedRow(rowData, new string[0]); Assert.AreEqual <bool>(true, reader.IsEOF); }