public async Task TimeZoneConversionsAsync()
        {
            var pd = new MockProcessDisplay();

            var writeFile = (CsvFile)m_WriteFile.Clone();

            writeFile.FileName = UnitTestInitializeCsv.GetTestPath("BasicCSVOut2tzc.txt");

            FileSystemUtils.FileDelete(writeFile.FileName);
            var setting = UnitTestHelper.ReaderGetAllFormats();

            UnitTestInitializeCsv.MimicSQLReader.AddSetting(setting);
            writeFile.SqlStatement = setting.ID;
            writeFile.FileFormat.FieldDelimiter = "|";
            writeFile.ColumnCollection.AddIfNew(
                new Column("DateTime", new ValueFormatMutable()
            {
                DataType = DataType.DateTime, DateFormat = "yyyyMMdd"
            })
            {
                TimePartFormat = @"hh:mm",
                TimePart       = "Time",
                TimeZonePart   = "TZ"
            });
            var writer = new CsvFileWriter(writeFile, pd);

            var res = await writer.WriteAsync(writeFile.SqlStatement, 360, null, pd.CancellationToken);

            Assert.IsTrue(FileSystemUtils.FileExists(writeFile.FileName));
            Assert.AreEqual(1065, res, "Records");
        }
        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);
        }
示例#3
0
        public async Task FileCopy()
        {
            var dest = UnitTestInitializeCsv.GetTestPath("xyz.txt");

            try
            {
                using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                {
                    processDisplay.Maximum = -100;

                    Assert.IsFalse(FileSystemUtils.FileExists(dest));
                    await FileSystemUtils.FileCopy(UnitTestInitializeCsv.GetTestPath("AllFormats.txt"), dest, false,
                                                   processDisplay);

                    Assert.IsTrue(FileSystemUtils.FileExists(dest));
                    Assert.AreEqual(-100, processDisplay.Maximum);

                    // Copy again, the old file should be overwritten
                    await FileSystemUtils.FileCopy(UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt"), dest, true,
                                                   processDisplay);

                    Assert.IsTrue(FileSystemUtils.FileExists(dest));
                    Assert.AreEqual(new FileInfo(UnitTestInitializeCsv.GetTestPath("AlternateTextQualifiers.txt")).Length,
                                    new FileInfo(dest).Length);
                }
            }
            finally
            {
                FileSystemUtils.FileDelete(dest);
            }
        }
        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 WriteDataTableAsync()
        {
            using (var dataTable = new DataTable {
                TableName = "DataTable", Locale = CultureInfo.InvariantCulture
            })
            {
                dataTable.Columns.Add("ID", typeof(int));
                dataTable.Columns.Add("Text", typeof(string));
                for (var i = 0; i < 100; i++)
                {
                    var row = dataTable.NewRow();
                    row["ID"]   = i;
                    row["Text"] = i.ToString(CultureInfo.CurrentCulture);
                    dataTable.Rows.Add(row);
                }

                var writeFile = new CsvFile {
                    ID = "Test.txt", FileName = UnitTestInitializeCsv.GetTestPath("Test.txt"), SqlStatement = "Hello"
                };
                using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                {
                    var writer = new CsvFileWriter(writeFile, processDisplay);
                    using (var reader = new DataTableWrapper(dataTable))
                    {
                        // await reader.OpenAsync(processDisplay.CancellationToken);
                        Assert.AreEqual(100, await writer.WriteAsync(reader, processDisplay.CancellationToken));
                    }
                }

                Assert.IsTrue(File.Exists(writeFile.FileName));
            }
        }
        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 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());
            }
        }
示例#8
0
        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 void OpenReadTestGZipLargeRead()
        {
            using (var res = new ImprovedStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("Larger.json.gz"), true)))
            {
                Assert.IsNotNull(res);

                var result1 = new byte[10000];

                // read a potion that is larger than the buffered stream
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result1, 0, result1.Length);
                }

                // should return to the start
                res.Seek(0, SeekOrigin.Begin);
                var result2 = new byte[10000];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result2, 0, result2.Length);
                }

                Assert.AreEqual(result1[0], result2[0]);
                Assert.AreEqual(result1[1], result2[1]);
                Assert.AreEqual(result1[2], result2[2]);
                Assert.AreEqual(result1[3], result2[3]);
                Assert.AreEqual(result1[4], result2[4]);
                Assert.AreEqual(result1[5], result2[5]);
            }
        }
示例#10
0
 public async Task GuessStartRowAsync()
 {
     using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"))))
         Assert.AreEqual(
             0,
             await improvedStream.GuessStartRow(65001, "\t", "\"", "", UnitTestInitializeCsv.Token), "BasicCSV.txt");
 }
        public void Init()
        {
            m_ReadFile =
                new CsvFile(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"))
            {
                ID         = "Read",
                FileFormat = { FieldDelimiter = ",", CommentLine = "#" }
            };

            m_ReadFile.ColumnCollection.AddIfNew(new Column("ExamDate",
                                                            new ValueFormatMutable()
            {
                DataType = DataType.DateTime, DateFormat = @"dd/MM/yyyy"
            }));
            m_ReadFile.ColumnCollection.AddIfNew(new Column("Score", DataType.Integer));
            m_ReadFile.ColumnCollection.AddIfNew(new Column("Proficiency", DataType.Numeric));
            m_ReadFile.ColumnCollection.AddIfNew(new Column("IsNativeLang", DataType.Boolean)
            {
                Ignore = true
            });

            UnitTestInitializeCsv.MimicSQLReader.AddSetting(m_ReadFile);

            m_WriteFile = new CsvFile {
                ID = "Write", SqlStatement = m_ReadFile.ID
            };

            m_WriteFile.ColumnCollection.AddIfNew(new Column("ExamDate", @"MM/dd/yyyy")
            {
                TimePart = "ExamTime"
            });
            m_WriteFile.ColumnCollection.AddIfNew(new Column {
                Name = "Proficiency", Ignore = true
            });
        }
示例#12
0
        public async Task ReadJSon3Async()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason3.json"))
            {
                JsonFormat = true
            };

            using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                using (var jfr = new JsonFileReader(setting, dpd))
                {
                    await jfr.OpenAsync(dpd.CancellationToken);

                    Assert.AreEqual(2, jfr.FieldCount);
                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual(28L, jfr.GetValue(0));
                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual(56L, jfr.GetValue(0));
                    while (await jfr.ReadAsync(dpd.CancellationToken))
                    {
                    }

                    Assert.AreEqual(5, jfr.RecordNumber);
                }
        }
示例#13
0
 public async Task GuessStartRowWithCommentsAsync()
 {
     using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("LongHeaders.txt"))))
         Assert.AreEqual(
             0,
             await improvedStream.GuessStartRow(65001, ",", "\"", "#", UnitTestInitializeCsv.Token), "LongHeaders.txt");
 }
示例#14
0
        public async Task ReadJSon1TypedAsync()
        {
            var setting =
                new CsvFile(UnitTestInitializeCsv.GetTestPath("Larger.json"))
            {
                JsonFormat = true
            };

            using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
            {
                using (var jfr = new JsonFileReader(setting, processDisplay))
                {
                    await jfr.OpenAsync(processDisplay.CancellationToken);

                    await jfr.ReadAsync(processDisplay.CancellationToken);

                    Assert.AreEqual(new Guid("ef21069c-3d93-4e07-878d-00e820727f65"), jfr.GetGuid(0));
                    Assert.IsTrue((new DateTime(2020, 04, 03, 18, 45, 29, 573, DateTimeKind.Utc) -
                                   jfr.GetDateTime(1).ToUniversalTime()).TotalSeconds < 2);
                    Assert.AreEqual((short)0, jfr.GetInt16(5));
                    Assert.AreEqual((int)0, jfr.GetInt32(5));
                    Assert.AreEqual((long)0, jfr.GetInt64(5));
                    var val = new object[jfr.FieldCount];
                    jfr.GetValues(val);
                    Assert.IsNull(val[2]);
                }
            }
        }
示例#15
0
        public async Task ReadJSon2Async()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason2.json"))
            {
                JsonFormat = true
            };

            using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                using (var jfr = new JsonFileReader(setting, dpd))
                {
                    await jfr.OpenAsync(dpd.CancellationToken);

                    Assert.AreEqual(7, jfr.FieldCount);
                    await jfr.ReadAsync(dpd.CancellationToken);

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("Loading defaults C:\\Users\\rnoldner\\AppData\\Roaming\\CSVFileValidator\\Setting.xml",
                                    jfr.GetValue(6));
                    while (await jfr.ReadAsync(dpd.CancellationToken))
                    {
                    }

                    Assert.AreEqual(29, jfr.RecordNumber);
                }
        }
        public void OpenReadTestGZipSmallRead()
        {
            using (var res = new ImprovedStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCsV.txt.gz"), true)))
            {
                Assert.IsNotNull(res);
                var result1 = new byte[2048];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result1, 0, result1.Length);
                }

                // should return to teh start
                res.Seek(0, SeekOrigin.Begin);
                var result2 = new byte[2048];
                using (var reader = new BinaryReader(res))
                {
                    reader.Read(result2, 0, result2.Length);
                }

                Assert.AreEqual(result1[0], result2[0]);
                Assert.AreEqual(result1[1], result2[1]);
                Assert.AreEqual(result1[2], result2[2]);
                Assert.AreEqual(result1[3], result2[3]);
                Assert.AreEqual(result1[4], result2[4]);
                Assert.AreEqual(result1[5], result2[5]);
            }
        }
        private void WriteFile(string fileName, string password, string internalName, bool remove = false)
        {
            var fullname = UnitTestInitializeCsv.GetTestPath(fileName);

            var          encoding = EncodingHelper.GetEncoding(65001, true);
            const string c_Line1  = "This is a test of compressed data written to a file";
            const string c_Line2  = "Yet another line to be written";
            const string c_Line3  = "A text with non ASCII characters: Raphael Nöldner";

            var sourceAccsss = new SourceAccess(fullname, false);

            if (string.IsNullOrEmpty(password))
            {
                sourceAccsss.EncryptedPassphrase = password;
            }
            if (!string.IsNullOrEmpty(internalName))
            {
                sourceAccsss.IdentifierInContainer = internalName;
            }

            using (var improvedStream = new ImprovedStream(sourceAccsss))
            {
                using (var writer = new StreamWriter(improvedStream, encoding, 8192))
                {
                    writer.WriteLine(c_Line1);
                    writer.WriteLine(c_Line2);
                    writer.WriteLine(c_Line3);
                    writer.WriteLine();
                    writer.WriteLine(c_Line1);
                }

                improvedStream.Close();
            }

            Assert.IsTrue(FileSystemUtils.FileExists(fullname), "Check if File is created" + fileName);
            sourceAccsss = new SourceAccess(fullname, true);
            if (string.IsNullOrEmpty(password))
            {
                sourceAccsss.EncryptedPassphrase = password;
            }

            using (var improvedStream = new ImprovedStream(sourceAccsss))
            {
                using (var textReader = new StreamReader(improvedStream, encoding, true))
                {
                    Assert.AreEqual(c_Line1, textReader.ReadLine(), "Line 1 : " + fileName);
                    Assert.AreEqual(c_Line2, textReader.ReadLine(), "Line 2 : " + fileName);
                    Assert.AreEqual(c_Line3, textReader.ReadLine(), "Line 3 : " + fileName);
                    Assert.AreEqual(string.Empty, textReader.ReadLine(), "Line 4 : " + fileName);
                    Assert.AreEqual(c_Line1, textReader.ReadLine(), "Line 5 : " + fileName);
                }

                improvedStream.Close();
            }

            if (remove)
            {
                FileSystemUtils.FileDelete(fullname);
            }
        }
 public void OpenReadTestRegular()
 {
     using (var res = new ImprovedStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("BasicCsV.txt"), true)))
     {
         Assert.IsNotNull(res);
     }
 }
        public void ImprovedTextReaderPositionStoreTestFromMiddle()
        {
            using (var impStream = new ImprovedStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("txTranscripts.txt"), true)))
            {
                using (var test = new ImprovedTextReader(impStream, 65001, 1))
                {
                    test.ToBeginning();
                    Assert.AreEqual(2, test.LineNumber);
                    Assert.AreEqual(
                        @"GCS_004805_Osipova	023c25d3-3420-449c-a75b-0d74d29ddc38	Completed	04/02/2008 00:00:00	04/02/2008 00:00:00	04/02/2008 00:00:00",
                        test.ReadLine());
                    var    lastLine1 = string.Empty;
                    string lastLine2;
                    for (var i = 0; i < 5; i++)
                    {
                        lastLine1 = test.ReadLine();
                    }
                    var store    = new ImprovedTextReaderPositionStore(test);
                    var readLine = false;
                    while (!store.AllRead())
                    {
                        lastLine2 = test.ReadLine();
                        // since there are buffers its we will not end up with the excact same line, but we need
                        // to at least have read the line.
                        if (lastLine2 == lastLine1)
                        {
                            readLine = true;
                        }
                    }

                    Assert.IsTrue(readLine);
                }
            }
        }
示例#20
0
        public async Task OpenLogAsync()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("LogFile.json"))
            {
                JsonFormat = true
            };

            using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                using (var jfr = new JsonFileReader(setting, dpd))
                {
                    await jfr.OpenAsync(dpd.CancellationToken);

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("level", jfr.GetColumn(1).Name);
                    Assert.AreEqual("Error", jfr.GetValue(1));

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("Reading EdgeAPI vw_rpt_transcript", jfr.GetValue(2));

                    await jfr.ReadAsync(dpd.CancellationToken);

                    Assert.AreEqual("System.Data.DataException", jfr.GetValue(4));
                }
        }
        public async Task ColumnErrorDictionaryTest1Async()
        {
            var setting = new CsvFile
            {
                FileName       = UnitTestInitializeCsv.GetTestPath("Sessions.txt"),
                HasFieldHeader = true,
                ByteOrderMark  = true,
                FileFormat     = { FieldDelimiter = "\t" }
            };

            setting.ColumnCollection.AddIfNew(new Column("Start Date")
            {
                Ignore = true
            });

            using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                using (var reader = new CsvFileReader(setting, processDisplay))
                {
                    await reader.OpenAsync(processDisplay.CancellationToken);

                    var test1 = new ColumnErrorDictionary(reader);
                    Assert.IsNotNull(test1);

                    // Message in ignored column
                    reader.HandleWarning(0, "Msg1");
                    reader.HandleError(1, "Msg2");

                    Assert.AreEqual("Msg2", test1.Display);
                }
        }
        public async Task StartAsyncTestAsync()
        {
            var  myDataTable    = new DataTable();
            bool beginCalled    = false;
            bool finishedCalled = false;
            bool warningCalled  = false;
            bool refeshCalled   = false;

            Task refeshFunc(FilterType FilterType, CancellationToken CancellationToken) => Task.Run(() => refeshCalled = true);

            using (var tsde = new TwoStepDataTableLoader(dt => myDataTable = dt, () => myDataTable, refeshFunc, null, () => beginCalled = true, (x) => finishedCalled = true))
            {
                var csv = new CsvFile
                {
                    FileName   = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt"),
                    FileFormat = { FieldDelimiter = ",", CommentLine = "#" }
                };

                using (var proc = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                {
                    await tsde.StartAsync(csv, true, TimeSpan.FromMilliseconds(20), proc, (sender, args) => { warningCalled = true; });

                    Assert.IsTrue(refeshCalled);
                    Assert.IsFalse(warningCalled);
                    Assert.IsTrue(beginCalled);
                    Assert.IsTrue(finishedCalled);

                    Assert.AreEqual(8, myDataTable.Columns.Count());
                }
            }
        }
示例#23
0
 public async Task GuessStartRow12Async()
 {
     using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("SkippingEmptyRowsWithDelimiter.txt"))))
         Assert.AreEqual(
             12,
             await improvedStream.GuessStartRow(-1, ",", "\"", "", UnitTestInitializeCsv.Token), "SkippingEmptyRowsWithDelimiter.txt");
 }
        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);
        }
示例#25
0
 public void CsvTextDisplayShow()
 {
     using (var frm = new FormCsvTextDisplay(UnitTestInitializeCsv.GetTestPath("BasicCSV.txt")))
     {
         UnitTestWinFormHelper.ShowFormAndClose(frm, .2,
                                                (f) => f.OpenFile(false, "\"", "\t", "", 1200, 1, "##"));
     }
 }
        public async Task AllFormatsPipeReaderAsync()
        {
            var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("RealignColumn.txt"))
            {
                HasFieldHeader        = true,
                FileFormat            = { FieldDelimiter = "\t" },
                TryToSolveMoreColumns = true,
                AllowRowCombining     = true,
                SkipEmptyLines        = false
            };

            using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
                using (var test = new CsvFileReader(setting, processDisplay))
                {
                    await test.OpenAsync(processDisplay.CancellationToken);

                    // first five rows are good.
                    await test.ReadAsync(processDisplay.CancellationToken); // Line 2

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 3

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 4

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 5

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 6

                    // Issue row Column 3 = Text|6
                    await test.ReadAsync(processDisplay.CancellationToken); // Line 6

                    Assert.AreEqual("Text\tF", test.GetValue(3));

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 7

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 8

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 9

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 10

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 11

                    Assert.AreEqual("Memo: A long text, \t multiple words 11", test.GetValue(5));
                    await test.ReadAsync(processDisplay.CancellationToken); // Line 12

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 13

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 14

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 15

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 16

                    await test.ReadAsync(processDisplay.CancellationToken); // Line 17

                    Assert.AreEqual("Memo: A long text\nmultiple words 17", test.GetValue(5));
                }
        }
示例#27
0
        public async Task NewCsvFileGuessAllTestEmptyAsync()
        {
            using (var display = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
            {
                var det = await CsvHelper.GetDetectionResultFromFile(UnitTestInitializeCsv.GetTestPath("CSVTestEmpty.txt"), display);

                Assert.AreEqual(0, det.SkipRows);
            }
        }
示例#28
0
        public async Task GuessHeaderSkippingEmptyRowsWithDelimiterAsync()
        {
            using (var improvedStream = FunctionalDI.OpenStream(new SourceAccess(UnitTestInitializeCsv.GetTestPath("SkippingEmptyRowsWithDelimiter.txt"))))
            {
                var result = await improvedStream.GuessHasHeader(65001, 0, "#", ",", UnitTestInitializeCsv.Token);

                Assert.IsFalse(result.Item1);
            }
        }
示例#29
0
 public void GetFileReader()
 {
     m_CsvFile.FileName = UnitTestInitializeCsv.GetTestPath("BasicCSV.txt");
     using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
         using (var res = FunctionalDI.GetFileReader(m_CsvFile, TimeZoneInfo.Local.Id, processDisplay))
         {
             Assert.IsInstanceOfType(res, typeof(IFileReader));
         }
 }
示例#30
0
        public async Task NewCsvFileGuessAllSmallFile()
        {
            using (var display = new CustomProcessDisplay(UnitTestInitializeCsv.Token))
            {
                var det = await CsvHelper.GetDetectionResultFromFile(UnitTestInitializeCsv.GetTestPath("employee.txt"), display, true);

                Assert.AreEqual(RecordDelimiterType.CRLF, det.NewLine);
            }
        }