예제 #1
0
        public void ReadTableReaderTest()
        {
            DataTable table = CreateTestTableAndText(out string tableText);

            using (StringReader reader = new(tableText))
            {
                DataTable?newTable = CsvUtility.ReadTable(reader);
                TestReadTable(table, newTable);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }