Ejemplo n.º 1
0
        public void Render_OneViolationWithOneRecordOfOneField_Correct()
        {
            var candidateTable = new DataTable()
            {
                TableName = "MyTable"
            };

            candidateTable.Columns.Add(new DataColumn("ForeignKey"));
            candidateTable.Columns.Add(new DataColumn("Numeric value"));
            candidateTable.Columns.Add(new DataColumn("Boolean value"));
            candidateTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            candidateTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var foreignKeyDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("ForeignKey"), Role = ColumnRole.Key
            };
            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Numeric value"), Role = ColumnRole.Value
            };

            var keyMappings = new ColumnMappingCollection()
            {
                new ColumnMapping(foreignKeyDefinition.Identifier, ColumnType.Text)
            };
            var valueMappings = new ColumnMappingCollection()
            {
                new ColumnMapping(numericDefinition.Identifier, ColumnType.Numeric)
            };

            var records = new List <LookupMatchesViolationRecord>()
            {
                new LookupMatchesViolationRecord()
                {
                    { candidateTable.Columns[1], new LookupMatchesViolationData(false, 15) },
                },
            };
            var association = new LookupMatchesViolationComposite(candidateTable.Rows[0], records);

            var sampler = new FullSampler <LookupMatchesViolationComposite>();

            sampler.Build(new[] { association });
            var msg = new LookupTableHelperJson(new[] { association }
                                                , new[] { foreignKeyDefinition, numericDefinition }
                                                , sampler);
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                using (var writer = new JsonTextWriter(sw))
                {
                    msg.Render(writer);
                    var value = sb.ToString();
                    Console.WriteLine(value);
                    Assert.That(value, Is.StringContaining(",\"rows\":[[\"Alpha\",{\"value\":\"10\",\"expectation\":\"15\"},\"True\"]]}"));
                }
        }
Ejemplo n.º 2
0
        public void GetExcludedRowCount_EmptyList_0()
        {
            var values = new int[0];

            var sampler = new FullSampler <int>();

            sampler.Build(values);

            Assert.That(sampler.GetExcludedRowCount, Is.EqualTo(0));
        }
Ejemplo n.º 3
0
        public void IsSampled_EmptyList_False()
        {
            var values = new int[0];

            var sampler = new FullSampler <int>();

            sampler.Build(values);

            Assert.That(sampler.GetIsSampled, Is.False);
        }
Ejemplo n.º 4
0
        public void GetResult_EmptyList_Empty()
        {
            var values = new int[0];

            var sampler = new FullSampler <int>();

            sampler.Build(values);

            Assert.That(sampler.GetResult(), Is.Empty);
        }
Ejemplo n.º 5
0
        public void GetExcludedRowCount_NonEmptyList_0()
        {
            var values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var sampler = new FullSampler <int>();

            sampler.Build(values);

            Assert.That(sampler.GetExcludedRowCount, Is.EqualTo(0));
        }
Ejemplo n.º 6
0
        public void IsSampled_NonEmptyList_False()
        {
            var values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var sampler = new FullSampler <int>();

            sampler.Build(values);

            Assert.That(sampler.GetIsSampled, Is.False);
        }
Ejemplo n.º 7
0
        public void GetResult_NonEmptyList_Empty()
        {
            var values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var sampler = new FullSampler <int>();

            sampler.Build(values);

            Assert.That(sampler.GetResult().Count(), Is.EqualTo(10));
        }
Ejemplo n.º 8
0
        public void Render_OneViolationWithOneRecordOfTwoWrongFields_Correct()
        {
            var candidateTable = new DataTable()
            {
                TableName = "MyTable"
            };

            candidateTable.Columns.Add(new DataColumn("Id"));
            candidateTable.Columns.Add(new DataColumn("ForeignKey"));
            candidateTable.Columns.Add(new DataColumn("Numeric value"));
            candidateTable.Columns.Add(new DataColumn("Boolean value"));
            candidateTable.LoadDataRow(new object[] { 1, "Alpha", 10, true }, false);
            candidateTable.LoadDataRow(new object[] { 2, "Beta", 20, false }, false);

            var foreignKeyDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("ForeignKey"), Role = ColumnRole.Key
            };
            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Numeric value"), Role = ColumnRole.Value
            };
            var booleanDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Boolean value"), Role = ColumnRole.Value
            };

            var records = new List <LookupMatchesViolationRecord>()
            {
                new LookupMatchesViolationRecord()
                {
                    { candidateTable.Columns[2], new LookupMatchesViolationData(false, 15) },
                    { candidateTable.Columns[3], new LookupMatchesViolationData(false, false) },
                },
            };
            var association = new LookupMatchesViolationComposite(candidateTable.Rows[0], records);

            var sampler = new FullSampler <LookupMatchesViolationComposite>();

            sampler.Build(new[] { association });
            var msg = new LookupTableHelperMarkdown(new[] { association }
                                                    , new[] { foreignKeyDefinition, numericDefinition, booleanDefinition }
                                                    , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();

            Console.WriteLine(value);
            Assert.That(value.Count(c => c == '\n'), Is.EqualTo(6));
            Assert.That(value, Does.Contain("| 10 <> 15"));
            Assert.That(value, Does.Contain("| True <> False"));
        }
Ejemplo n.º 9
0
        protected override void RenderAnalysis(LookupViolationCollection violations, IEnumerable <ColumnMetadata> metadata, ISampler <DataRow> sampler, ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings, JsonWriter writer)
        {
            writer.WriteStartObject();
            writer.WritePropertyName("non-matching");
            var localSampler = new FullSampler <LookupMatchesViolationComposite>();
            var rows         = violations.Values.Where(x => x is LookupMatchesViolationInformation)
                               .Cast <LookupMatchesViolationInformation>()
                               .SelectMany(x => x.CandidateRows);

            localSampler.Build(rows);
            var tableHelper = new LookupTableHelperJson(rows, metadata, localSampler);

            tableHelper.Render(writer);
            writer.WriteEndObject();
        }
        protected override void RenderAnalysis(LookupViolationCollection violations, IEnumerable <ColumnMetadata> metadata, ISampler <DataRow> sampler, ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings, MarkdownContainer container)
        {
            container.Append("Analysis".ToMarkdownHeader());
            var state = violations.Values.Select(x => x.State).First();

            container.Append(GetExplanationText(violations, state).ToMarkdownParagraph());

            var fullSampler = new FullSampler <LookupMatchesViolationComposite>();
            var rows        = violations.Values.Where(x => x is LookupMatchesViolationInformation)
                              .Cast <LookupMatchesViolationInformation>()
                              .SelectMany(x => x.CandidateRows);

            fullSampler.Build(rows);
            var tableHelper = new LookupTableHelperMarkdown(rows, metadata, fullSampler);

            tableHelper.Render(container);
        }
Ejemplo n.º 11
0
        public void Build_TwoRowsByOrdinal_FirstRow()
        {
            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"));
            dataTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            dataTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var idDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#0"), Role = ColumnRole.Key
            };
            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#1"), Role = ColumnRole.Value
            };
            var booleanDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#2"), Role = ColumnRole.Value
            };

            var sampler = new FullSampler <DataRow>();

            sampler.Build(dataTable.Rows.Cast <DataRow>());
            var msg = new StandardTableHelperMarkdown(dataTable.Rows.Cast <DataRow>()
                                                      , new ColumnMetadata[] { idDefinition, numericDefinition, booleanDefinition }
                                                      , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();

            Assert.That(value.Count(c => c == '\n'), Is.EqualTo(7));

            var indexes = value.IndexOfAll('\n').ToArray();

            var titleLine = value.Substring(indexes[1] + 1, indexes[2] - indexes[1] - 2);

            Assert.That(titleLine.Replace(" ", ""), Is.EqualTo("#0(Id)|#1(Numericvalue)|#2(Booleanvalue)"));
        }
Ejemplo n.º 12
0
        public void Build_TwoRowsByOrdinal_FirstRow()
        {
            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"));
            dataTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            dataTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var idDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#0"), Role = ColumnRole.Key
            };
            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#1"), Role = ColumnRole.Value, Type = ColumnType.Numeric
            };
            var booleanDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#2"), Role = ColumnRole.Value, Type = ColumnType.Boolean
            };

            var sampler = new FullSampler <DataRow>();

            sampler.Build(dataTable.Rows.Cast <DataRow>());
            var msg = new StandardTableHelperJson(dataTable.Rows.Cast <DataRow>()
                                                  , new ColumnMetadata[] { idDefinition, numericDefinition, booleanDefinition }
                                                  , sampler);
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                using (var writer = new JsonTextWriter(sw))
                {
                    msg.Render(writer);
                    var value = sb.ToString();
                    Console.WriteLine(value);
                    Assert.That(sb.ToString, Is.StringContaining("{\"position\":0,\"name\":\"Id\",\"role\":\"KEY\",\"type\":\"Text\"}"));
                    Assert.That(sb.ToString, Is.StringContaining("{\"position\":1,\"name\":\"Numeric value\",\"role\":\"VALUE\",\"type\":\"Numeric\"}"));
                    Assert.That(sb.ToString, Is.StringContaining("{\"position\":2,\"name\":\"Boolean value\",\"role\":\"VALUE\",\"type\":\"Boolean\"}"));
                }
        }
Ejemplo n.º 13
0
        public void Build_TwoRows_ColumnDelimitersAlligned()
        {
            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"));
            dataTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            dataTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var idDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("#0"), Role = ColumnRole.Key
            };

            var sampler = new FullSampler <DataRow>();

            sampler.Build(dataTable.Rows.Cast <DataRow>());
            var msg = new StandardTableHelperMarkdown(dataTable.Rows.Cast <DataRow>()
                                                      , new ColumnMetadata[] { idDefinition }
                                                      , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();
            var lines = value.Replace("\n", string.Empty).Split('\r');

            int pos = 0;

            while ((pos = lines[0].IndexOf('|', pos + 1)) > 0)
            {
                foreach (var line in lines.TakeWhile(l => l.Length > 0))
                {
                    Assert.That(line[pos], Is.EqualTo('|'), "The line '{0}' was expecting to have a '|' at position {1} but it was a '{2}'", new object[] { line, pos, line[pos] });
                }
            }
        }
Ejemplo n.º 14
0
        public void Build_TwoRows_SevenLines()
        {
            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"));
            dataTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            dataTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var idDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Id"), Role = ColumnRole.Key
            };

            var sampler = new FullSampler <DataRow>();

            sampler.Build(dataTable.Rows.Cast <DataRow>());
            var msg = new StandardTableHelperMarkdown(dataTable.Rows.Cast <DataRow>()
                                                      , new ColumnMetadata[] { idDefinition }
                                                      , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();

            Assert.That(value.Count(c => c == '\n'), Is.EqualTo(7));

            var indexes  = value.IndexOfAll('\n').ToArray();
            var dashLine = value.Substring(indexes[3] + 1, indexes[4] - indexes[3] - 2);

            Assert.That(dashLine.Distinct().Count(), Is.EqualTo(3));
            Assert.That(dashLine.Distinct(), Has.Member(' '));
            Assert.That(dashLine.Distinct(), Has.Member('-'));
            Assert.That(dashLine.Distinct(), Has.Member('|'));
        }
Ejemplo n.º 15
0
        public void Build_TwoRows_5Lines()
        {
            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"));
            dataTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            dataTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var idDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Id"), Role = ColumnRole.Key
            };

            var sampler = new FullSampler <DataRow>();

            sampler.Build(dataTable.Rows.Cast <DataRow>());
            var msg = new StandardTableHelperJson(dataTable.Rows.Cast <DataRow>()
                                                  , new ColumnMetadata[] { idDefinition }
                                                  , sampler);
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                using (var writer = new JsonTextWriter(sw))
                {
                    msg.Render(writer);
                    var value = sb.ToString();
                    Console.WriteLine(value);
                    Assert.That(sb.ToString, Is.StringContaining("\"total-rows\":2"));
                    Assert.That(sb.ToString, Is.StringContaining("\"table\":{\"columns\":[{"));
                    Assert.That(sb.ToString, Is.StringContaining("{\"position\":0,\"name\":\"Id\",\"role\":\"KEY\",\"type\":\"Text\"}"));
                    Assert.That(sb.ToString, Is.StringContaining("\"rows\":[[\"Alpha\",\"10\",\"True\"],["));
                }
        }
Ejemplo n.º 16
0
        public void Build_TwoRows_NumericValuesNonRounded()
        {
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            var numericDataColumn = new DataColumn("Numeric value");

            numericDataColumn.ExtendedProperties.Add("NBi::Type", ColumnType.Numeric);
            dataTable.Columns.Add(numericDataColumn);
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            dataTable.LoadDataRow(new object[] { "Alpha", 10.752, true }, false);
            dataTable.LoadDataRow(new object[] { "Beta", 20.8445585, false }, false);

            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Numeric value"), Role = ColumnRole.Value, Type = ColumnType.Numeric
            };

            var sampler = new FullSampler <DataRow>();

            sampler.Build(dataTable.Rows.Cast <DataRow>());
            var msg = new StandardTableHelperMarkdown(dataTable.Rows.Cast <DataRow>()
                                                      , new ColumnMetadata[] { numericDefinition }
                                                      , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();
            var lines = value.Replace("\n", string.Empty).Split('\r');

            Assert.That(value, Is.StringContaining("10.752 "));
            Assert.That(value, Is.StringContaining("20.8445585"));
        }
Ejemplo n.º 17
0
        public void Render_TwoViolationsForSameKey_Correct()
        {
            var candidateTable = new DataTable()
            {
                TableName = "MyTable"
            };

            candidateTable.Columns.Add(new DataColumn("Id"));
            candidateTable.Columns.Add(new DataColumn("ForeignKey"));
            candidateTable.Columns.Add(new DataColumn("Numeric value"));
            candidateTable.Columns.Add(new DataColumn("Boolean value"));
            candidateTable.LoadDataRow(new object[] { 1, "Alpha", 10, true }, false);
            candidateTable.LoadDataRow(new object[] { 2, "Alpha", 20, false }, false);

            var foreignKeyDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("ForeignKey"), Role = ColumnRole.Key
            };
            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Numeric value"), Role = ColumnRole.Value, Type = ColumnType.Numeric
            };
            var booleanDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Boolean value"), Role = ColumnRole.Value, Type = ColumnType.Boolean
            };

            var records = new List <LookupMatchesViolationRecord>()
            {
                new LookupMatchesViolationRecord()
                {
                    { candidateTable.Columns[2], new LookupMatchesViolationData(false, "17.0") },
                    { candidateTable.Columns[3], new LookupMatchesViolationData(false, false) },
                },
                new LookupMatchesViolationRecord()
                {
                    { candidateTable.Columns[2], new LookupMatchesViolationData(false, "12") },
                    { candidateTable.Columns[3], new LookupMatchesViolationData(false, false) },
                },
                new LookupMatchesViolationRecord()
                {
                    { candidateTable.Columns[2], new LookupMatchesViolationData(false, "18") },
                    { candidateTable.Columns[3], new LookupMatchesViolationData(true, true) },
                },
            };
            var firstAssociation  = new LookupMatchesViolationComposite(candidateTable.Rows[0], records);
            var secondAssociation = new LookupMatchesViolationComposite(candidateTable.Rows[1], records);

            var sampler = new FullSampler <LookupMatchesViolationComposite>();

            sampler.Build(new[] { firstAssociation, secondAssociation });
            var msg = new LookupTableHelperMarkdown(new[] { firstAssociation, secondAssociation }
                                                    , new[] { foreignKeyDefinition, numericDefinition, booleanDefinition }
                                                    , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();

            Console.WriteLine(value);
            Assert.That(value.Count(c => c == '\n'), Is.EqualTo(11));
            Assert.That(value, Does.Contain("Result-set with 2 rows"));
            Assert.That(value, Does.Contain("#0 (Id) | #1 (ForeignKey) | #2 (Numeric value) | #3 (Boolean value)"));
            Assert.That(value, Does.Contain("1       | Alpha           | 10 <> 17           | True <> False"));
            Assert.That(value, Does.Contain(">>      | >>              | 10 <> 12           | True <> False"));
            Assert.That(value, Does.Contain(">>      | >>              | 10 <> 18           | True"));
            Assert.That(value, Does.Contain("2       | Alpha           | 20 <> 17           | False <> False"));
            Assert.That(value, Does.Contain(">>      | >>              | 20 <> 12           | False <> False"));
            Assert.That(value, Does.Contain(">>      | >>              | 20 <> 18           | False"));
        }
Ejemplo n.º 18
0
        public void Render_OneViolationWithOneRecordOfOneField_Correct()
        {
            var candidateTable = new DataTable()
            {
                TableName = "MyTable"
            };

            candidateTable.Columns.Add(new DataColumn("ForeignKey"));
            candidateTable.Columns.Add(new DataColumn("Numeric value"));
            candidateTable.Columns.Add(new DataColumn("Boolean value"));
            candidateTable.LoadDataRow(new object[] { "Alpha", 10, true }, false);
            candidateTable.LoadDataRow(new object[] { "Beta", 20, false }, false);

            var foreignKeyDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("ForeignKey"), Role = ColumnRole.Key
            };
            var numericDefinition = new ColumnMetadata()
            {
                Identifier = new ColumnIdentifierFactory().Instantiate("Numeric value"), Role = ColumnRole.Value
            };

            var keyMappings = new ColumnMappingCollection()
            {
                new ColumnMapping(foreignKeyDefinition.Identifier, ColumnType.Text)
            };
            var valueMappings = new ColumnMappingCollection()
            {
                new ColumnMapping(numericDefinition.Identifier, ColumnType.Numeric)
            };

            var records = new List <LookupMatchesViolationRecord>()
            {
                new LookupMatchesViolationRecord()
                {
                    { candidateTable.Columns[1], new LookupMatchesViolationData(false, 15) },
                },
            };
            var association = new LookupMatchesViolationComposite(candidateTable.Rows[0], records);

            var sampler = new FullSampler <LookupMatchesViolationComposite>();

            sampler.Build(new[] { association });
            var msg = new LookupTableHelperMarkdown(new[] { association }
                                                    , new[] { foreignKeyDefinition, numericDefinition }
                                                    , sampler);
            var container = new MarkdownContainer();

            msg.Render(container);
            var value = container.ToMarkdown();

            Console.WriteLine(value);

            Assert.That(value.Count(c => c == '\n'), Is.EqualTo(6));

            var indexes  = value.IndexOfAll('\n').ToArray();
            var dashLine = value.Substring(indexes[3] + 1, indexes[4] - indexes[3] - 2);

            Assert.That(dashLine.Distinct().Count(), Is.EqualTo(3));
            Assert.That(dashLine.Distinct(), Has.Member(' '));
            Assert.That(dashLine.Distinct(), Has.Member('-'));
            Assert.That(dashLine.Distinct(), Has.Member('|'));
        }