public void RenderExpected_OneRow_ReturnCorrectNumberOfRowsOnTopWithoutPlurial()
        {
            var dataSet   = new DataSet();
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < 1; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }

            var samplers = new SamplersFactory <DataRow>().Instantiate(FailureReportProfile.Default);
            var msg      = new DataRowsMessageMarkdown(EngineStyle.ByIndex, samplers);

            msg.BuildComparaison(dataTable.Rows.Cast <DataRow>(), null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');


            Assert.That(lines[0], Is.EqualTo("Result-set with 1 row"));
        }
        public void RenderExpected_MoreThanMaxRowsCount_ReturnSampleRowsCountAndHeaderAndSeparation()
        {
            var dataSet   = new DataSet();
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < 20; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }

            var samplers = new SamplersFactory <DataRow>().Instantiate(FailureReportProfile.Default);
            var msg      = new DataRowsMessageMarkdown(EngineStyle.ByIndex, samplers);

            msg.BuildComparaison(dataTable.Rows.Cast <DataRow>(), null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');


            Assert.That(lines.Count(l => l.Contains("|")), Is.EqualTo(10 + 3));
        }
        public void RenderExpected_MoreThanMaxRowsCount_ReturnCorrectCountOfSkippedRow()
        {
            var dataSet   = new DataSet();
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < 22; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }

            var samplers = new SamplersFactory <DataRow>().Instantiate(FailureReportProfile.Default);
            var msg      = new DataRowsMessageMarkdown(EngineStyle.ByIndex, samplers);

            msg.BuildComparaison(dataTable.Rows.Cast <DataRow>(), null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');
            //Not exactly the last line but the previous due to paragraph rendering.
            var lastLine = lines.Reverse().ElementAt(1);

            Assert.That(lastLine, Is.EqualTo("12 (of 22) rows have been skipped for display purpose."));
        }
        public void RenderExpected_MoreThanSampleRowsCountButLessThanMaxRowsCountWithSpecificProfile_ReturnEachRowAndHeaderAndSeparation()
        {
            var rowCount = 120;
            var threshold = rowCount + 20;
            var max = threshold / 2;

            var dataSet = new DataSet();
            var dataTable = new DataTable() { TableName = "MyTable" };
            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < rowCount; i++)
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);

            var profile = Mock.Of<IFailureReportProfile>(p =>
                p.MaxSampleItem == max
                && p.ThresholdSampleItem == threshold
                && p.ExpectedSet == FailureReportSetType.Sample
            );
            var samplers = new SamplersFactory<DataRow>().Instantiate(profile);
            var msg = new DataRowsMessageJson(EngineStyle.ByIndex, samplers);
            msg.BuildComparaison(dataTable.Rows.Cast<DataRow>(), null, null);
            var value = msg.RenderExpected();
            Assert.That(value, Is.Not.StringContaining("\"sampled-rows\":"));

            value = value.Substring(value.IndexOf("\"rows\""));

            Assert.That(value.Count(x => x == '['), Is.EqualTo(rowCount + 1));
        }
Beispiel #5
0
        public void RenderExpected_MoreThanSampleRowsCountButLessThanMaxRowsCount_ReturnEachRowAndHeaderAndSeparation()
        {
            var rowCount = 12;

            var dataSet   = new DataSet();
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < rowCount; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }

            var samplers = new SamplersFactory <DataRow>().Instantiate(FailureReportProfile.Default);
            var msg      = new DataRowsMessageJson(EngineStyle.ByIndex, samplers);

            msg.BuildComparaison(dataTable.Rows.Cast <DataRow>(), null, null);

            var value = msg.RenderExpected();

            Assert.That(value, Does.Not.Contain("\"sampled-rows\":"));

            value = value.Substring(value.IndexOf("\"rows\""));
            Assert.That(value.Count(x => x == '['), Is.EqualTo(rowCount + 1));
        }
        public void RenderCompared_WithSpecialRows_DisplayTextForThisKindOfRows(
            int missingRowCount
            , int unexpectedRowCount
            , int duplicatedRowCount
            , int keyMatchingRowCount
            , int nonMatchingValueRowCount
            , string expectedText)
        {
            var compared = ResultResultSet.Build(
                    GetDataRows(missingRowCount)
                    , GetDataRows(unexpectedRowCount)
                    , GetDataRows(duplicatedRowCount)
                    , GetDataRows(keyMatchingRowCount)
                    , GetDataRows(nonMatchingValueRowCount)
                );


            var samplers = new SamplersFactory<DataRow>().Instantiate(FailureReportProfile.Default);
            var msg = new DataRowsMessageJson(EngineStyle.ByIndex, samplers);
            msg.BuildComparaison(null, null, compared);
            var value = msg.RenderAnalysis();

            Assert.That(value, Is.StringContaining($"\"{expectedText}\":{{\"total-rows\":3"));
            Assert.That(value, Is.Not.StringContaining($"\"{expectedText}\":{{\"total-rows\":3}}}}"));
        }
        public void RenderExpected_MoreThanSampleRowsAndMaxRowsCountWithSpecificFailureReportProfile_ReturnEachRowAndHeaderAndSeparation()
        {
            var rowCount  = 120;
            var threshold = rowCount - 20;
            var max       = threshold / 2;

            var list = new List <string>();

            for (int i = 0; i < rowCount; i++)
            {
                list.Add(String.Format("Item {0:00}", i));
            }

            var profile = Mock.Of <IFailureReportProfile>(p =>
                                                          p.MaxSampleItem == max &&
                                                          p.ThresholdSampleItem == threshold &&
                                                          p.ExpectedSet == FailureReportSetType.Sample
                                                          );


            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(profile);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(list, null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');


            Assert.That(lines.Count(l => l.Contains("*")), Is.EqualTo(max));
        }
Beispiel #8
0
        public void RenderMessage_NoAdditional_IncludeTimestamp()
        {
            var samplers = new SamplersFactory <DataRow>().Instantiate(FailureReportProfile.Default);
            var msg      = new DataRowsMessageJson(EngineStyle.ByIndex, samplers);
            var value    = msg.RenderMessage();

            Assert.That(value, Does.Contain($"\"timestamp\":\"{DateTime.Now.Year}-"));
            Console.WriteLine(value);
        }
        public IDataRowsMessageFormatter Instantiate(IFailureReportProfile profile, Core.ResultSet.EngineStyle style)
        {
            var factory  = new SamplersFactory <DataRow>();
            var samplers = factory.Instantiate(profile);

            switch (profile.Format)
            {
            case FailureReportFormat.Markdown:
                return(new DataRowsMessageMarkdown(style, samplers));

            case FailureReportFormat.Json:
                return(new DataRowsMessageJson(style, samplers));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #10
0
        public IItemsMessageFormatter Instantiate(IFailureReportProfile profile)
        {
            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(profile);

            switch (profile.Format)
            {
            case FailureReportFormat.Markdown:
                return(new ItemsMessageMarkdown(samplers));

            case FailureReportFormat.Json:
                return(new ItemsMessageJson(samplers));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public void RenderExpected_MoreThanMaxRowsCount_ReturnCorrectNumberOfRowsOnTop()
        {
            var dataSet = new DataSet();
            var dataTable = new DataTable() { TableName = "MyTable" };
            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < 20; i++)
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);

            var samplers = new SamplersFactory<DataRow>().Instantiate(FailureReportProfile.Default);
            var msg = new DataRowsMessageJson(EngineStyle.ByIndex, samplers);
            msg.BuildComparaison(dataTable.Rows.Cast<DataRow>(), null, null);
            var value = msg.RenderExpected();

            Assert.That(value, Is.StringContaining("\"total-rows\":20"));
        }
        public void RenderExpected_OneRow_ReturnCorrectNumberOfRowsOnTopWithoutPlurial()
        {
            var list = new List <string>();

            list.Add("Item 01");


            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(FailureReportProfile.Default);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(list, null, null);
            var value     = msg.RenderExpected();
            var lines     = value.Replace("\n", string.Empty).Split('\r');
            var firstLine = lines[0];

            Assert.That(firstLine, Is.EqualTo("Set of 1 item"));
        }
        public void RenderExpected_LessThanMaxRowsCount_DoesntDisplaySkippedRow(int rowCount)
        {
            var list = new List <string>();

            for (int i = 0; i < rowCount; i++)
            {
                list.Add(String.Format("Item {0:00}", i));
            }

            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(FailureReportProfile.Default);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(list, null, null);
            var value = msg.RenderExpected();

            Assert.That(value, Is.Not.StringContaining(" others not displayed."));
        }
Beispiel #14
0
        public ILookupViolationsMessageFormatter Instantiate(IFailureReportProfile profile)
        {
            var dataRowsFactory  = new SamplersFactory <DataRow>();
            var dataRowsSamplers = dataRowsFactory.Instantiate(profile);

            var keysCollectionFactory  = new SamplersFactory <KeyCollection>();
            var keysCollectionSamplers = keysCollectionFactory.Instantiate(profile);

            switch (profile.Format)
            {
            case FailureReportFormat.Markdown:
                return(new LookupViolationsMessageMarkdown(keysCollectionSamplers, dataRowsSamplers));

            case FailureReportFormat.Json:
                return(new ReferenceViolationsMessageJson(dataRowsSamplers));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public void RenderCompared_WithSpecialRows_DisplayTextForThisKindOfRows(
            int missingRowCount
            , int unexpectedRowCount
            , string expectedText)
        {
            var compared = new ListComparer.Result(
                GetDataRows(missingRowCount)
                , GetDataRows(unexpectedRowCount)
                );

            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(FailureReportProfile.Default);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(null, null, compared);
            var value = msg.RenderAnalysis();

            Assert.That(value, Is.StringContaining(expectedText));
        }
        public void RenderExpected_MoreThanMaxRowsCount_ReturnCorrectNumberOfRowsOnTop()
        {
            var list = new List <string>();

            for (int i = 0; i < 20; i++)
            {
                list.Add(String.Format("Item {0:00}", i));
            }

            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(FailureReportProfile.Default);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(list, null, null);
            var value     = msg.RenderExpected();
            var lines     = value.Replace("\n", string.Empty).Split('\r');
            var firstLine = lines[0];

            Assert.That(firstLine, Is.EqualTo("Set of 20 items"));
        }
        public void RenderExpected_MoreThanMaxRowsCount_ReturnSampleRowsCountAndHeaderAndSeparation()
        {
            var list = new List <string>();

            for (int i = 0; i < 20; i++)
            {
                list.Add(String.Format("Item {0:00}", i));
            }


            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(FailureReportProfile.Default);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(list, null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');


            Assert.That(lines.Count(l => l.Contains("*")), Is.EqualTo(10));
        }
        public void RenderExpected_MoreThanMaxRowsCount_ReturnCorrectCountOfSkippedRow()
        {
            var list = new List <string>();

            for (int i = 0; i < 22; i++)
            {
                list.Add(String.Format("Item {0:00}", i));
            }

            var factory  = new SamplersFactory <string>();
            var samplers = factory.Instantiate(FailureReportProfile.Default);

            var msg = new ItemsMessageMarkdown(samplers);

            msg.Build(list, null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');
            //Not exactly the last line but the previous due to paragraph rendering.
            var lastLine = lines.Reverse().ElementAt(1);

            Assert.That(lastLine, Is.EqualTo("... and 12 others not displayed."));
        }
Beispiel #19
0
        public void RenderExpected_LessThanMaxRowsCount_DoesntDisplaySkippedRow(int rowCount)
        {
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < rowCount; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }

            var samplers = new SamplersFactory <DataRow>().Instantiate(FailureReportProfile.Default);
            var msg      = new DataRowsMessageMarkdown(EngineStyle.ByIndex, samplers);

            msg.BuildComparaison(dataTable.Rows.Cast <DataRow>(), null, null);
            var value = msg.RenderExpected();

            Assert.That(value, Does.Not.Contain("rows have been skipped for display purpose."));
        }
        public void RenderExpected_MoreThanSampleRowsCountButLessThanMaxRowsCountWithSpecificProfileNone_ReturnEachRowAndHeaderAndSeparation()
        {
            var rowCount  = 120;
            var threshold = rowCount - 20;
            var max       = threshold / 2;

            var dataSet   = new DataSet();
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < rowCount; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }

            var profile = Mock.Of <IFailureReportProfile>(p =>
                                                          p.MaxSampleItem == max &&
                                                          p.ThresholdSampleItem == threshold &&
                                                          p.ExpectedSet == FailureReportSetType.None
                                                          );

            var samplers = new SamplersFactory <DataRow>().Instantiate(profile);
            var msg      = new DataRowsMessageMarkdown(EngineStyle.ByIndex, samplers);

            msg.BuildComparaison(dataTable.Rows.Cast <DataRow>(), null, null);
            var value = msg.RenderExpected();
            var lines = value.Replace("\n", string.Empty).Split('\r');


            Assert.That(lines.Count(l => l.Contains("|")), Is.EqualTo(0));
            Assert.That(lines, Has.All.EqualTo("Display skipped."));
        }