public void ReadTableReaderTest() { DataTable table = CreateTestTableAndText(out string tableText); using (StringReader reader = new(tableText)) { DataTable?newTable = CsvUtility.ReadTable(reader); TestReadTable(table, newTable); } }
public void ReadTableFileTest() { string tableFileName = FileUtility.GetTempFileName(".csv"); try { DataTable table = CreateTestTable(); CsvUtility.WriteTable(tableFileName, table); DataTable?newTable = CsvUtility.ReadTable(tableFileName); TestReadTable(table, newTable); } finally { FileUtility.DeleteFile(tableFileName); } }
public void ReadTableReaderCustomTest() { DataTable table = CreateTestTableAndText(out string tableText); using (StringReader reader = new(tableText)) { DataTable?newTable = CsvUtility.ReadTable(reader, preLoadTable => { int columnCount = preLoadTable.Columns.Count; for (int i = 0; i < columnCount; i++) { // Get the column types from the first test data row (just like CreateTestTable()). preLoadTable.Columns[i].DataType = TestData[1, i].GetType(); } preLoadTable.PrimaryKey = new[] { preLoadTable.Columns[0] }; }); TestReadTable(table, newTable, treatAsStrings: false); } }