public void CsvComparisonErrorsMissingTest()
        {
            var expectedCsv = CsvTable.Parse("SimpleExpected.csv");
            var actualCsv   = CsvTable.Parse("SimpleActualMissing.csv");
            var comparison  = new CsvComparison(expectedCsv, actualCsv, Tolerance.Parse("2%;0.001"));
            var expected    = comparison.ExpectedTable;

            Assert.AreEqual(2, expected.RowCount, "Expected RowCount");
            var actual = comparison.ActualTable;

            Assert.AreEqual(1, actual.RowCount, "Actual RowCount");
            Assert.AreEqual(4, comparison.ErrorCount(), "Error Count = 2");
            var query    = comparison.Query();
            var errorRow = query[0] as Collection <object>;

            Assert.AreEqual("B1", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
            errorRow = query[1] as Collection <object>;
            Assert.AreEqual("B2", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
            errorRow = query[2] as Collection <object>;
            Assert.AreEqual("A3", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
            errorRow = query[3] as Collection <object>;
            Assert.AreEqual("B3", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
        }
        public void CsvComparisonDifferenceQueryTest()
        {
            var baseTable      = CreateTestTable("100.0", "100.0", "100.0", "100.0");
            var compareTable   = CreateTestTable("102.1", "100.5", "97.5", "105.1");
            var csvComparison2 = new CsvComparison(baseTable, compareTable, Tolerance.Parse("2%"));

            Assert.AreEqual(3, csvComparison2.ErrorCount(), "Error count 2%");

            var csvComparison5 = new CsvComparison(baseTable, compareTable, Tolerance.Parse("5%"));

            Assert.AreEqual(1, csvComparison5.ErrorCount(), "Error count 5%");

            var difference = new CsvComparisonDifference(csvComparison2, csvComparison5);

            Assert.AreEqual(2, difference.ErrorCount, "Error Count difference");

            var expectedDifference = new List <List <string> >
            {
                new List <string> {
                    "B2", "2", "Attr1", "2 (B)", "Stream1", "102.1 != 100", "2.1"
                },
                new List <string> {
                    "B4", "4", "Attr3", "2 (B)", "Stream1", "97.5 != 100", "2.5"
                }
            };

            var i = 0;

            foreach (Collection <object> row in difference.Query())
            {
                Assert.AreEqual(expectedDifference[i][0], CsvComparisonTest.QueryValue(row, "Cell"), $"Query Entry #{i}.Cell"); Assert.AreEqual(expectedDifference[i][1], CsvComparisonTest.QueryValue(row, "Row No"), $"Query Entry #{i}.RowNo");
                Assert.AreEqual(expectedDifference[i][2], CsvComparisonTest.QueryValue(row, "Row Name"), $"Query Entry #{i}.Row");
                Assert.AreEqual(expectedDifference[i][3], CsvComparisonTest.QueryValue(row, "Column No"), $"Query Entry #{i}.ColumnNo");
                Assert.AreEqual(expectedDifference[i][4], CsvComparisonTest.QueryValue(row, "Column Name"), $"Query Entry #{i}.Column");
                Assert.AreEqual(expectedDifference[i][5], CsvComparisonTest.QueryValue(row, "Value"), $"Query Entry #{i}.Value");
                Assert.AreEqual(expectedDifference[i][6], CsvComparisonTest.QueryValue(row, "Delta"), $"Query Entry #{i}.Delta");
                i++;
            }

            i = 0;
            foreach (Collection <object> row in difference.DoTable(null).Skip(1))
            {
                Assert.AreEqual("report:" + expectedDifference[i][0], row[0], $"Table Entry #{i}.Cell");
                Assert.AreEqual("report:" + expectedDifference[i][1], row[1], $"Table Entry #{i}.RowNo");
                Assert.AreEqual("report:" + expectedDifference[i][2], row[2], $"Table Entry #{i}.Row");
                Assert.AreEqual("report:" + expectedDifference[i][3], row[3], $"Table Entry #{i}.ColumnNo");
                Assert.AreEqual("report:" + expectedDifference[i][4], row[4], $"Table Entry #{i}.Column");
                Assert.AreEqual("fail:" + expectedDifference[i][5], row[5], $"Table Entry #{i}.Value");
                Assert.AreEqual("fail:" + expectedDifference[i][6], row[6], $"Table Entry #{i}.Delta");
                i++;
            }
            Assert.AreEqual(expectedDifference.Count, difference.ErrorCount, "Table ErrorCount");
        }
示例#3
0
        public void CsvComparisonDataQueryTest()
        {
            Assert.AreEqual(_expectedResult.Count, _csvComparison.ErrorCount(), "Error count");
            var i = 0;

            foreach (Collection <object> row in _csvComparison.Query())
            {
                Assert.AreEqual(_expectedResult[i][0], QueryValue(row, "Cell"), $"Query Entry #{i}.Cell");
                Assert.AreEqual(_expectedResult[i][1], QueryValue(row, "Row No"), $"Query Entry #{i}.RowNo");
                Assert.AreEqual(_expectedResult[i][2], QueryValue(row, "Row Name"), $"Query Entry #{i}.Row");
                Assert.AreEqual(_expectedResult[i][3], QueryValue(row, "Column No"), $"Query Entry #{i}.ColumnNo");
                Assert.AreEqual(_expectedResult[i][4], QueryValue(row, "Column Name"), $"Query Entry #{i}.Column");
                Assert.AreEqual(_expectedResult[i][5], QueryValue(row, "Value"), $"Query Entry #{i}.Value");
                i++;
            }
        }
        public void CsvComparisonErrorsSurplusTest()
        {
            var expectedCsv = CsvTable.Parse("SimpleExpected.csv");
            var actualCsv   = CsvTable.Parse("SimpleActualSurplus.csv");
            var comparison  = new CsvComparison(expectedCsv, actualCsv, Tolerance.Parse("2%;0.001"));

            Assert.AreEqual(3, comparison.ErrorCount(), "Error Count = 3");
            var query    = comparison.Query();
            var errorRow = query[0] as Collection <object>;

            Assert.AreEqual("C1", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Surplus", QueryValue(errorRow, "Issue"));
            errorRow = query[1] as Collection <object>;
            Assert.AreEqual("C2", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Surplus", QueryValue(errorRow, "Issue"));
            errorRow = query[2] as Collection <object>;
            Assert.AreEqual("A4", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Surplus", QueryValue(errorRow, "Issue"));
        }
        public void CsvComparisonErrorsStreamDataTest()
        {
            var baseCsv = CsvTable.Parse("StreamData1.csv");

            Console.WriteLine($"Base: columns={baseCsv.ColumnCount}; rows={baseCsv.RowCount}");
            var newCsv = CsvTable.Parse("StreamData2.csv");

            Console.WriteLine($"New: columns={newCsv.ColumnCount}; rows={newCsv.RowCount}");
            var comparison = new CsvComparison(baseCsv, newCsv, Tolerance.Parse("2%;0.001"));

            Assert.AreEqual(1, comparison.ErrorCount(), "Error Count = 1");
            var query    = comparison.Query();
            var errorRow = query[0] as Collection <object>;

            Assert.AreEqual("H2", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("2", QueryValue(errorRow, "Row No"));
            Assert.AreEqual("Total Liquid Mole Fraction", QueryValue(errorRow, "Row Name"));
            Assert.AreEqual("8 (H)", QueryValue(errorRow, "Column No"));
            Assert.AreEqual("A11", QueryValue(errorRow, "Column Name"));
            Assert.AreEqual("0.01 != 0", QueryValue(errorRow, "Value"));
            Assert.AreEqual("0.01", QueryValue(errorRow, "Delta"));
            Assert.IsTrue(string.IsNullOrEmpty(QueryValue(errorRow, "Delta %").ToString()));
        }