Exemplo n.º 1
0
        public void TestWarningsRecordWithMapping()
        {
            using (var test = new CsvFileReader(m_ValidSetting))
            {
                test.Open(false, CancellationToken.None);
                var dataTable = new DataTable
                {
                    TableName = "DataTable",
                    Locale    = CultureInfo.InvariantCulture
                };

                dataTable.Columns.Add(test.GetName(0), test.GetFieldType(0));

                var recordNumberColumn = dataTable.Columns.Add(test.RecordNumberFieldName, typeof(int));
                recordNumberColumn.AllowDBNull = true;

                var lineNumberColumn = dataTable.Columns.Add(test.EndLineNumberFieldName, typeof(int));
                lineNumberColumn.AllowDBNull = true;

                int[] columnMapping = { 0 };
                var   warningsList  = new RowErrorCollection();
                test.CopyRowToTable(dataTable, warningsList, columnMapping, recordNumberColumn, lineNumberColumn, null);
                var dataRow = dataTable.NewRow();
                test.Read();

                //warningsList.Add(-1, "Test1");
                //warningsList.Add(0, "Test2");
                //test.AssignNumbersAndWarnings(dataRow, columnMapping, recordNumberColumn, lineNumberColumn, null, warningsList);

                //Assert.AreEqual("Test1", dataRow.RowError);
                //Assert.AreEqual("Test2", dataRow.GetColumnError(0));
            }
        }
Exemplo n.º 2
0
        public void TryGetValue()
        {
            var coll = new RowErrorCollection(5);

            coll.Add(this, new WarningEventArgs(1, 1, "Message1", 100, 100, "ColName"));
            Assert.IsTrue(coll.TryGetValue(1, out var val));
        }
Exemplo n.º 3
0
        public void DisplayByRecordNumber()
        {
            var coll = new RowErrorCollection(5);

            coll.Add(this, new WarningEventArgs(425, 1, "Message1", 100, 100, "ColName"));
            Assert.IsTrue(coll.DisplayByRecordNumber.Contains("Row 425"));
        }
        public void WarningListAddEmpty()
        {
            var messageList = new RowErrorCollection(10);

            Assert.AreEqual(0, messageList.CountRows);

            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                messageList.Add(null, new WarningEventArgs(1, 2, null, 0, 0, null));
                Assert.Fail("Exception not thrown");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                messageList.Add(null, new WarningEventArgs(1, 2, string.Empty, 0, 0, null));
                Assert.Fail("Exception not thrown");
            }
            catch (ArgumentException)
            {
            }
        }
Exemplo n.º 5
0
        public void Clear()
        {
            var coll = new RowErrorCollection(5);

            coll.Add(this, new WarningEventArgs(1, 1, "Message1", 100, 100, "ColName"));
            Assert.AreEqual(1, coll.CountRows);
            coll.Clear();
            Assert.AreEqual(0, coll.CountRows);
        }
Exemplo n.º 6
0
        public void WarningListDisplay2()
        {
            var messageList = new RowErrorCollection();

            messageList.Add(null, new WarningEventArgs(1, 1, "Text1", 0, 1, null));
            messageList.Add(null, new WarningEventArgs(1, 2, "Text2", 0, 2, null));
            Assert.IsTrue(
                "Text1" + ErrorInformation.cSeparator + "Text2" == messageList.Display ||
                "Text2" + ErrorInformation.cSeparator + "Text1" == messageList.Display);
        }
Exemplo n.º 7
0
        public void WarningListAddAndClear()
        {
            var messageList = new RowErrorCollection();

            Assert.AreEqual(0, messageList.CountRows);

            messageList.Add(null, new WarningEventArgs(1, 2, "Line1", 0, 0, null));
            Assert.AreEqual(1, messageList.CountRows);
            messageList.Clear();
            Assert.AreEqual(0, messageList.CountRows);
        }
Exemplo n.º 8
0
        public void CsvDataReaderWriteToDataTable2()
        {
            var wl = new RowErrorCollection();

            using (var test = new CsvFileReader(m_ValidSetting))
            {
                test.Open(false, CancellationToken.None);
                var res = test.WriteToDataTable(m_ValidSetting, 2, wl, CancellationToken.None);
                Assert.AreEqual(2, res.Rows.Count);
                Assert.AreEqual(
                    6 + (m_ValidSetting.DisplayStartLineNo ? 1 : 0) + (m_ValidSetting.DisplayEndLineNo ? 1 : 0) +
                    (m_ValidSetting.DisplayRecordNo ? 1 : 0), res.Columns.Count);
            }
        }
        public void WarningListCombineWarning()
        {
            var messageList = new RowErrorCollection(10);

            messageList.Add(null, new WarningEventArgs(1, 1, "Text1", 0, 0, null));
            messageList.Add(null, new WarningEventArgs(1, 1, "Text2", 0, 1, null));
            Assert.AreEqual(1, messageList.CountRows);
            Assert.IsTrue(
                "Text1" + ErrorInformation.cSeparator + "Text2" == messageList.Display ||
                "Text2" + ErrorInformation.cSeparator + "Text1" == messageList.Display);
            _ = new ColumnErrorDictionary();
            messageList.TryGetValue(1, out var ce);
            Assert.AreEqual(1, ce.Count);
            Assert.AreEqual(messageList.Display, ce.Display);
        }
Exemplo n.º 10
0
        public void Add()
        {
            var coll = new RowErrorCollection(5);

            coll.Add(this, new WarningEventArgs(1, 1, "Message1", 100, 100, "ColName"));
            Assert.AreEqual(1, coll.CountRows);
            coll.Add(this, new WarningEventArgs(2, 1, "Message1", 101, 101, "ColName"));
            Assert.AreEqual(2, coll.CountRows);
            coll.Add(this, new WarningEventArgs(3, 1, "Message1", 102, 102, "ColName"));
            Assert.AreEqual(3, coll.CountRows);
            coll.Add(this, new WarningEventArgs(4, 1, "Message1", 103, 103, "ColName"));
            Assert.AreEqual(4, coll.CountRows);
            coll.Add(this, new WarningEventArgs(5, 1, "Message1", 104, 104, "ColName"));
            Assert.AreEqual(5, coll.CountRows);

            /// This should be cut off
            coll.Add(this, new WarningEventArgs(6, 1, "Message1", 105, 105, "ColName"));
            Assert.AreEqual(5, coll.CountRows);
        }
Exemplo n.º 11
0
        public void CsvDataReaderInitWarnings()
        {
            var setting = new CsvFile
            {
                FileName       = Path.Combine(m_ApplicationDirectory, "BasicCSV.txt"),
                HasFieldHeader = false,
                SkipRows       = 1
            };

            setting.FileFormat.FieldQualifier = "XX";
            setting.FileFormat.FieldDelimiter = ",,";
            var warningList = new RowErrorCollection();

            using (var test = new CsvFileReader(setting))
            {
                test.Warning += warningList.Add;
                test.Open(false, CancellationToken.None);
                Assert.IsTrue(warningList.Display.Contains("Only the first character of 'XX' is be used for quoting."));
                Assert.IsTrue(warningList.Display.Contains("Only the first character of ',,' is used as delimiter."));
            }
        }
        public async Task HandleIgnoredColumns()
        {
            var coll = new RowErrorCollection(5);

            using (var reader = new CsvFileReader(UnitTestInitializeCsv.GetTestPath("AllFormats.txt"), Encoding.UTF8.CodePage, 0, true,
                                                  new IColumn[]
            {
                new ImmutableColumn("DateTime", new ImmutableValueFormat(DataType.DateTime), 0, true, "", true),
                new ImmutableColumn("Integer", new ImmutableValueFormat(DataType.Integer), 0, true, "", true),
            }))

            {
                await reader.OpenAsync(CancellationToken.None);

                coll.HandleIgnoredColumns(reader);

                // An error i an ignored column is not stored
                coll.Add(this, new WarningEventArgs(1, 0, "Message1", 100, 100, "ColName"));
                Assert.AreEqual(0, coll.CountRows);
            }
        }
Exemplo n.º 13
0
        public void WarningListAddEmpty()
        {
            var messageList = new RowErrorCollection();

            Assert.AreEqual(0, messageList.CountRows);

            try
            {
                messageList.Add(null, new WarningEventArgs(1, 2, null, 0, 0, null));
                Assert.Fail("Exception not thrown");
            }
            catch (System.ArgumentException)
            {
            }
            try
            {
                messageList.Add(null, new WarningEventArgs(1, 2, string.Empty, 0, 0, null));
                Assert.Fail("Exception not thrown");
            }
            catch (System.ArgumentException)
            {
            }
        }
Exemplo n.º 14
0
        public void IssueReader()
        {
            var basIssues = new CsvFile
            {
                TreatLFAsSpace        = true,
                TryToSolveMoreColumns = true,
                AllowRowCombining     = true,
                FileName = Path.Combine(m_ApplicationDirectory, "BadIssues.csv")
            };

            basIssues.FileFormat.FieldDelimiter = "TAB";
            basIssues.FileFormat.FieldQualifier = string.Empty;
            basIssues.ColumnAdd(new Column
            {
                DataType      = DataType.DateTime,
                DateFormat    = "yyyy/MM/dd",
                DateSeparator = "-",
                Name          = "effectiveDate"
            });
            basIssues.ColumnAdd(new Column
            {
                DataType      = DataType.DateTime,
                DateFormat    = "yyyy/MM/ddTHH:mm:ss",
                DateSeparator = "-",
                Name          = "timestamp"
            });
            basIssues.ColumnAdd(new Column
            {
                DataType = DataType.Integer,
                Name     = "version"
            });
            basIssues.ColumnAdd(new Column
            {
                DataType = DataType.Boolean,
                Name     = "retrainingRequired"
            });
            basIssues.ColumnAdd(new Column
            {
                DataType = DataType.Boolean,
                Name     = "classroomTraining"
            });
            basIssues.ColumnAdd(new Column
            {
                DataType = DataType.TextToHtml,
                Name     = "webLink"
            });
            var warningList = new RowErrorCollection();

            using (var test = new CsvFileReader(basIssues))
            {
                test.Warning += warningList.Add;
                test.Open(false, CancellationToken.None);
                // need 22 columns
                Assert.AreEqual(22, test.GetSchemaTable().Rows.Count());

                // This should work
                test.Read();
                Assert.AreEqual(0, warningList.CountRows);

                Assert.AreEqual("Eagle_sop020517", test.GetValue(0));
                Assert.AreEqual("de-DE", test.GetValue(2));

                // There are more columns
                test.Read();
                Assert.AreEqual(1, warningList.CountRows);
                Assert.AreEqual("Eagle_SRD-0137699", test.GetValue(0));
                Assert.AreEqual("de-DE", test.GetValue(2));
                Assert.AreEqual(3, test.StartLineNumber);

                test.Read();
                Assert.AreEqual("Eagle_600.364", test.GetValue(0));

                test.Read();
                Assert.AreEqual("Eagle_spt029698", test.GetValue(0));

                test.Read();
                Assert.AreEqual("Eagle_SRD-0137698", test.GetValue(0));
                Assert.AreEqual(2, warningList.CountRows);

                test.Read();
                Assert.AreEqual("Eagle_SRD-0138074", test.GetValue(0));

                test.Read();
                Assert.AreEqual("Eagle_SRD-0125563", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1004040002982", test.GetValue(0));
                Assert.AreEqual(3, warningList.CountRows);

                test.Read();
                Assert.AreEqual("doc_1004040002913", test.GetValue(0));
                Assert.AreEqual(10, test.StartLineNumber);
                Assert.AreEqual(5, warningList.CountRows);

                test.Read();
                Assert.AreEqual("doc_1003001000427", test.GetValue(0));
                Assert.AreEqual(12, test.StartLineNumber);

                test.Read();
                Assert.AreEqual("doc_1008017000611", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1004040000268", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1008011000554", test.GetValue(0));
                test.Read();
                Assert.AreEqual("doc_1003001000936", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1200000124471", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1200000134529", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1004040003504", test.GetValue(0));

                test.Read();
                Assert.AreEqual("doc_1200000016068", test.GetValue(0));

                test.Read();
            }
        }
Exemplo n.º 15
0
 public void WarningListInit()
 {
     var messageList = new RowErrorCollection();
 }