Пример #1
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"));
        }
        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);
        }
Пример #3
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"));
        }
Пример #4
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('|'));
        }