public async Task GetSourceColumnInformationTestAsync() { var setting = new CsvFile { ID = "ID122", FileName = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"), HasFieldHeader = true, DisplayStartLineNo = false, SqlStatement = "ID122", FileFormat = { FieldDelimiter = "," } }; using (var reader = new CsvFileReader(setting, null)) { UnitTestInitializeCsv.MimicSQLReader.AddSetting(setting.ID, await reader.GetDataTableAsync(0, false, setting.DisplayStartLineNo, setting.DisplayRecordNo, setting.DisplayEndLineNo, false, null, UnitTestInitializeCsv.Token)); } using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { var res1 = await DetermineColumnFormat.GetWriterColumnInformationAsync(setting.SqlStatement, setting.Timeout, setting.FileFormat.ValueFormatMutable, setting.ColumnCollection.ReadonlyCopy(), processDisplay.CancellationToken); Assert.AreEqual(6, res1.Count()); setting.SqlStatement = null; var res2 = await DetermineColumnFormat.GetSqlColumnNamesAsync(setting.SqlStatement, setting.Timeout, processDisplay.CancellationToken); Assert.AreEqual(0, res2.Count()); } }
public async Task GetDataTableAsync3() { using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { var test3 = new CsvFile(UnitTestInitializeCsv.GetTestPath("WithEoFChar.txt")) { FileFormat = { FieldDelimiter = "Tab" } }; test3.ColumnCollection.Add(new Column("Memo") { Ignore = true }); using (var test = new CsvFileReader(test3, processDisplay)) { await test.OpenAsync(processDisplay.CancellationToken); var dt = await test.GetDataTableAsync(-1, true, true, true, true, true, null, processDisplay.CancellationToken); // 10 columns 1 ignored one added for Start line one for Error Field one for Record No one // for Line end Assert.AreEqual((10 - 1) + 4, dt.Columns.Count); Assert.AreEqual(19, dt.Rows.Count); } } }
public async Task DetermineColumnFormatFillGuessColumnFormatWriterAsync() { var setting = new CsvFile { ID = "DetermineColumnFormatFillGuessColumnFormatWriter", FileName = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"), DisplayStartLineNo = false, HasFieldHeader = true, FileFormat = { FieldDelimiter = "," } }; using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) using (var reader = new CsvFileReader(setting, null)) { await reader.OpenAsync(processDisplay.CancellationToken); UnitTestInitializeCsv.MimicSQLReader.AddSetting(setting.ID, await reader.GetDataTableAsync(0, false, setting.DisplayStartLineNo, setting.DisplayRecordNo, setting.DisplayEndLineNo, false, null, UnitTestInitializeCsv.Token)); } var writer = new CsvFile { SqlStatement = setting.ID }; using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { await writer.FillGuessColumnFormatWriterAsync(true, processDisplay); Assert.AreEqual(6, writer.ColumnCollection.Count); } }
public async Task GetDataTableAsync2() { using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { var test2 = (CsvFile)m_ValidSetting.Clone(); test2.RecordLimit = 4; using (var test = new CsvFileReader(test2, processDisplay)) { await test.OpenAsync(processDisplay.CancellationToken); var dt = await test.GetDataTableAsync(-1, false, false, false, false, false, null, processDisplay.CancellationToken); Assert.AreEqual(test2.RecordLimit, dt.Rows.Count); } } }