public async Task FillGuessColumnFormatReaderTestAsync() { var setting = new CsvFile { ID = "DetermineColumnFormatFillGuessColumnFormatWriter", FileName = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"), HasFieldHeader = true, FileFormat = { FieldDelimiter = "," } }; var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, IgnoreIdColumns = false }; var result1 = await setting.FillGuessColumnFormatReaderAsync(false, true, fillGuessSettings, UnitTestInitializeCsv.Token); Assert.AreEqual(5, result1.Count); var result2 = await setting.FillGuessColumnFormatReaderAsync(true, false, fillGuessSettings, UnitTestInitializeCsv.Token); Assert.AreEqual(6, result2.Count); }
public async Task FillGuessColumnFormatIgnoreID() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"), FileFormat = { FieldDelimiter = "," }, HasFieldHeader = true }; // setting.TreatTextNullAsNull = true; var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, IgnoreIdColumns = true }; await setting.FillGuessColumnFormatReaderAsync(false, false, fillGuessSettings, UnitTestInitializeCsv.Token); Assert.IsTrue(setting.ColumnCollection.Get("ID") == null || setting.ColumnCollection.Get("ID")?.Convert == false); Assert.AreEqual(DataType.DateTime, setting.ColumnCollection.Get("ExamDate")?.ValueFormat?.DataType); Assert.AreEqual(DataType.Boolean, setting.ColumnCollection.Get("IsNativeLang")?.ValueFormat?.DataType); }
public async Task FillGuessColumnFormatDatePartsAsync() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("Sessions.txt"), HasFieldHeader = true, ByteOrderMark = true, FileFormat = { FieldDelimiter = "\t" } }; var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, DateParts = true, IgnoreIdColumns = true }; await setting.FillGuessColumnFormatReaderAsync(false, true, fillGuessSettings, UnitTestInitializeCsv.Token); Assert.AreEqual("Start Date", setting.ColumnCollection[0].Name, "Column 1 Start date"); Assert.AreEqual("Start Time", setting.ColumnCollection[1].Name, "Column 2 Start Time"); Assert.AreEqual("Start Time", setting.ColumnCollection[0].TimePart, "TimePart is Start Time"); Assert.AreEqual(DataType.DateTime, setting.ColumnCollection[0].ValueFormat.DataType); Assert.AreEqual("MM/dd/yyyy", setting.ColumnCollection[0].ValueFormat.DateFormat); Assert.AreEqual("HH:mm:ss", setting.ColumnCollection[1].ValueFormat.DateFormat); }
public async Task FillGuessColumnFormatTrailingColumnsAsync() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("AllFormatsColon.txt"), HasFieldHeader = true, ByteOrderMark = true, FileFormat = { FieldDelimiter = "," } }; setting.ColumnCollection.Clear(); var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, IgnoreIdColumns = true }; await setting.FillGuessColumnFormatReaderAsync(false, true, fillGuessSettings, UnitTestInitializeCsv.Token); // need to identify 5 typed column of the 11 existing Assert.AreEqual(7, setting.ColumnCollection.Count, "Number of recognized Columns"); var v1 = setting.ColumnCollection.First(x => x.Name == "DateTime"); var v2 = setting.ColumnCollection.First(x => x.Name == "Double"); var v3 = setting.ColumnCollection.First(x => x.Name == "Boolean"); Assert.AreEqual( DataType.DateTime, v1.ValueFormat.DataType, "DateTime (Date Time (dd/MM/yyyy))"); // a double will always be read as decimal from Csv Assert.AreEqual( DataType.Numeric, v2.ValueFormat.DataType, "Double (Money (High Precision) (0.#####))"); Assert.AreEqual( DataType.Boolean, v3.ValueFormat.DataType, "Boolean (Boolean)"); }
public async Task FillGuessColumnFormatReaderAsync_Parameter() { var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, IgnoreIdColumns = true }; var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("AllFormatsColon.txt"), HasFieldHeader = true, ByteOrderMark = true, FileFormat = { FieldDelimiter = "," }, }; try { // ReSharper disable once AssignNullToNotNullAttribute await DetermineColumnFormat.FillGuessColumnFormatReaderAsync(null, true, true, fillGuessSettings, UnitTestInitializeCsv.Token); } catch (ArgumentNullException) { } catch (Exception ex) { Assert.Fail("Wrong or exception thrown exception is : " + ex.GetType().Name); } try { // ReSharper disable once AssignNullToNotNullAttribute await setting.FillGuessColumnFormatReaderAsync(true, true, null, UnitTestInitializeCsv.Token); } catch (ArgumentNullException) { } catch (Exception ex) { Assert.Fail("Wrong or exception thrown exception is : " + ex.GetType().Name); } }
public async Task FillGuessColumnFormatTextColumnsAsync() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("AllFormatsColon.txt"), HasFieldHeader = true, ByteOrderMark = true, FileFormat = { FieldDelimiter = "," } }; var fillGuessSettings = new FillGuessSettings { IgnoreIdColumns = true }; await setting.FillGuessColumnFormatReaderAsync(true, true, fillGuessSettings, UnitTestInitializeCsv.Token); Assert.AreEqual(10, setting.ColumnCollection.Count); Assert.AreEqual(DataType.DateTime, setting.ColumnCollection[0].ValueFormat.DataType); Assert.AreEqual(DataType.Integer, setting.ColumnCollection[1].ValueFormat.DataType); Assert.AreEqual(DataType.Numeric, setting.ColumnCollection[2].ValueFormat.DataType); Assert.AreEqual(DataType.String, setting.ColumnCollection[4].ValueFormat.DataType); }
public async Task TestJson() { var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Larger.json")) { JsonFormat = true }; var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, IgnoreIdColumns = true }; Assert.AreEqual(0, setting.ColumnCollection.Count); await setting.FillGuessColumnFormatReaderAsync(false, true, fillGuessSettings, UnitTestInitializeCsv.Token); var expected = new Dictionary <string, DataType> { { "object_id", DataType.Guid }, { "_last_touched_dt_utc", DataType.DateTime }, { "classification_id", DataType.Guid }, { "email_option_id", DataType.Integer } }; foreach (var keyValue in expected) { var indexCol = setting.ColumnCollection.FirstOrDefault(x => x.Name.Equals(keyValue.Key, StringComparison.InvariantCultureIgnoreCase)); Assert.IsNotNull(indexCol, $"Column {keyValue.Key} not recognized"); Assert.AreEqual(keyValue.Value, indexCol.ValueFormat.DataType); } }
public async Task FillGuessColumnFormatGermanDateAndNumbersAsync() { var setting = new CsvFile { FileName = UnitTestInitializeCsv.GetTestPath("DateAndNumber.csv"), HasFieldHeader = true, FileFormat = { FieldQualifier = "Quote", FieldDelimiter = "Tab" }, CodePageId = 1252 }; var fillGuessSettings = new FillGuessSettings { DetectNumbers = true, DetectDateTime = true, DetectPercentage = true, DetectBoolean = true, DetectGUID = true, IgnoreIdColumns = true }; // setting.TreatTextNullAsNull = true; await setting.FillGuessColumnFormatReaderAsync(false, false, fillGuessSettings, UnitTestInitializeCsv.Token); Assert.IsNotNull(setting.ColumnCollection.Get(@"Betrag Brutto (2 Nachkommastellen)"), "Data Type recognized"); Assert.AreEqual( DataType.Numeric, setting.ColumnCollection.Get(@"Betrag Brutto (2 Nachkommastellen)")?.ValueFormat?.DataType, "Is Numeric"); Assert.AreEqual( ",", setting.ColumnCollection.Get(@"Betrag Brutto (2 Nachkommastellen)")?.ValueFormat?.DecimalSeparator, "Decimal Separator found"); Assert.AreEqual(DataType.DateTime, setting.ColumnCollection.Get(@"Erstelldatum Rechnung")?.ValueFormat?.DataType); }