Exemplo n.º 1
0
        public void Add_MixOfNameandIndex_NBiException()
        {
            var mappings = new ColumnMappingCollection();

            mappings.Add(new ColumnMapping("name", "name", ColumnType.Text));
            Assert.Throws <NBiException>(() => mappings.Add(new ColumnMapping("#1", "#1", ColumnType.Text)));
        }
Exemplo n.º 2
0
        public void Add_MixOfNameandIndexInOneMapping_NoException()
        {
            var mappings = new ColumnMappingCollection();

            mappings.Add(new ColumnMapping("name", "#0", ColumnType.Text));
            Assert.DoesNotThrow(() => mappings.Add(new ColumnMapping("name2", "#1", ColumnType.Text)));
        }
Exemplo n.º 3
0
        public void Execute_LargeVolumeChild_Fast(int maxItem)
        {
            var reference = BuildDataTable(new[] { "Key0", "Key1", "Key0" }, new[] { "Foo", "Bar", "Foo" }, new object[] { 1, 2, 3 });
            var child     = new DataTable();
            var dt        = child.Columns.Add("two");

            for (int i = 0; i < maxItem; i++)
            {
                var dr = child.NewRow();
                dr.SetField <object>(dt, i);
                child.Rows.Add(dr);
            }
            child.AcceptChanges();

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnNameIdentifier("two"), new ColumnNameIdentifier("two"), ColumnType.Numeric)
            };
            var referencer = new LookupExistsAnalyzer(mapping);
            var stopWatch  = new Stopwatch();

            stopWatch.Start();
            var violations = referencer.Execute(child, reference);

            stopWatch.Stop();
            Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(10));
        }
Exemplo n.º 4
0
        public void Execute_LargeVolumeChildAndReference_Fast(int maxItem)
        {
            var child   = new DataTable();
            var dtChild = child.Columns.Add("one");

            for (int i = 0; i < maxItem; i++)
            {
                var dr = child.NewRow();
                dr.SetField <object>(dtChild, i);
                child.Rows.Add(dr);
            }
            child.AcceptChanges();
            var reference = child.Copy();

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnNameIdentifier("one"), new ColumnNameIdentifier("one"), ColumnType.Numeric)
            };
            var referencer = new LookupExistsAnalyzer(mapping);
            var stopWatch  = new Stopwatch();

            stopWatch.Start();
            referencer.Execute(child, reference);
            stopWatch.Stop();
            Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(10));
        }
Exemplo n.º 5
0
        public void Matches_ResultSetService_CallToExecuteOnce()
        {
            var sut = new ResultSet();
            sut.Load("a;b;1");
            var sutMock = new Mock<IResultSetService>();
            sutMock.Setup(s => s.Execute())
                .Returns(sut);
            var sutService = sutMock.Object;

            var assert = new ResultSet();
            assert.Load("a;b");
            var assertMock = new Mock<IResultSetService>();
            assertMock.Setup(s => s.Execute())
                .Returns(assert);
            var assertService = assertMock.Object;

            var mappings = new ColumnMappingCollection()
            {
                new ColumnMapping(new ColumnOrdinalIdentifier(0), ColumnType.Text),
                new ColumnMapping(new ColumnOrdinalIdentifier(1), ColumnType.Text),
            };

            var lookupExists = new LookupExistsConstraint(assertService);
            lookupExists = lookupExists.Using(mappings);

            //Method under test
            lookupExists.Matches(sutService);

            //Test conclusion            
            sutMock.Verify(s => s.Execute(), Times.Once());
            assertMock.Verify(s => s.Execute(), Times.Once());
        }
Exemplo n.º 6
0
        public void Matches_ReferenceAnalyzer_CallToExecuteOnce()
        {
            var sut = new ResultSet();
            sut.Load("a;b;1");
            var sutMock = new Mock<IResultSetService>();
            sutMock.Setup(s => s.Execute())
                .Returns(sut);
            var sutService = sutMock.Object;

            var assert = new ResultSet();
            assert.Load("a;b");
            var assertMock = new Mock<IResultSetService>();
            assertMock.Setup(s => s.Execute())
                .Returns(assert);
            var assertService = assertMock.Object;

            var mappings = new ColumnMappingCollection()
            {
                new ColumnMapping(new ColumnOrdinalIdentifier(0), ColumnType.Text),
                new ColumnMapping(new ColumnOrdinalIdentifier(1), ColumnType.Text),
            };

            var lookupExists = new LookupExistsConstraint(assertService);
            var analyzer = new Mock<LookupExistsAnalyzer>(mappings);
            analyzer.Setup(x => x.Execute(It.IsAny<ResultSet>(), It.IsAny<ResultSet>())).Returns(new LookupExistsViolationCollection(null));
            lookupExists.Engine = analyzer.Object;

            //Method under test
            lookupExists.Matches(sutService);

            //Test conclusion            
            analyzer.Verify(x => x.Execute(sut, assert), Times.Once());
        }
        protected override void SpecificBuild()
        {
            var ctrXml = ConstraintXml as LookupExistsXml;

            ctrXml.ResultSet.Settings = ctrXml.Settings;

            var factory  = new ColumnIdentifierFactory();
            var mappings = new ColumnMappingCollection(
                ctrXml.Join?.Mappings
                .Select(mapping => new ColumnMapping(
                            factory.Instantiate(mapping.Candidate)
                            , factory.Instantiate(mapping.Reference)
                            , mapping.Type))
                .Union(
                    ctrXml.Join?.Usings.Select(@using => new ColumnMapping(
                                                   factory.Instantiate(@using.Column)
                                                   , @using.Type)
                                               )));

            var builder = new ResultSetServiceBuilder();

            builder.Setup(Helper.InstantiateResolver(ctrXml.ResultSet));
            builder.Setup(Helper.InstantiateAlterations(ctrXml.ResultSet));
            var service = builder.GetService();

            var ctr = ctrXml.IsReversed ? new LookupReverseExistsConstraint(service) : new LookupExistsConstraint(service);

            Constraint = ctr.Using(mappings);
        }
Exemplo n.º 8
0
        public void Execute_LargeVolumeCandidate_Fast(int maxItem)
        {
            var reference   = BuildDataTable(new[] { "Key0", "Key1", "Key0" }, new[] { "Foo", "Bar", "Foo" }, new object[] { 1, 2, 3 });
            var candidate   = new DataTable();
            var idColumn    = candidate.Columns.Add("id");
            var valueColumn = candidate.Columns.Add("value");
            var randomizer  = new Random();

            for (int i = 0; i < maxItem; i++)
            {
                var dr = candidate.NewRow();
                dr.SetField <object>(idColumn, i);
                dr.SetField <object>(valueColumn, randomizer.Next().ToString());
                candidate.Rows.Add(dr);
            }
            candidate.AcceptChanges();

            var mappingKey = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnNameIdentifier("id"), new ColumnNameIdentifier("two"), ColumnType.Numeric)
            };
            var mappingValue = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnNameIdentifier("value"), new ColumnNameIdentifier("one"), ColumnType.Text)
            };
            var analyzer  = new LookupMatchesAnalyzer(mappingKey, mappingValue);
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var violations = analyzer.Execute(candidate, reference);

            stopWatch.Stop();
            Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(7));
        }
        public void RenderMessage_NoneSamples_Correct()
        {
            var referenceTable = new DataTable()
            {
                TableName = "MyTable"
            };

            referenceTable.Columns.Add(new DataColumn("ForeignKey"));
            referenceTable.Columns.Add(new DataColumn("Numeric value"));
            referenceTable.LoadDataRow(new object[] { "Alpha", 15 }, false);
            referenceTable.LoadDataRow(new object[] { "Beta", 20 }, false);
            referenceTable.LoadDataRow(new object[] { "Delta", 30 }, false);

            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[] { "Gamma", 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 violations = new LookupExistsViolationCollection(keyMappings);

            violations.Register(new KeyCollection(new[] { "Gamma" }), candidateTable.Rows[1]);

            var samplers = new Dictionary <string, ISampler <DataRow> >()
            {
                { "candidate", new NoneSampler <DataRow>() },
                { "reference", new NoneSampler <DataRow>() },
                { "analysis", new NoneSampler <DataRow>() },
            };

            var message = new LookupExistsViolationMessageJson(samplers);

            message.Generate(referenceTable.Rows.Cast <DataRow>(), candidateTable.Rows.Cast <DataRow>(), violations, keyMappings, null);

            var text = message.RenderMessage();

            Assert.That(text, Does.Contain("\"actual\":{\"total-rows\":2}"));
            Assert.That(text, Does.Contain("\"expected\":{\"total-rows\":3}"));
            Assert.That(text, Does.Contain("\"analysis\":{\"unexpected\":{\"total-rows\":1}"));
        }
Exemplo n.º 10
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\"]]}"));
                }
        }
Exemplo n.º 11
0
        public void Add_MixOfNameAndOrdinalInSecondMapping_NoException()
        {
            var mappings = new ColumnMappingCollection()
            {
                new ColumnMapping(new ColumnNameIdentifier("zero"), new ColumnOrdinalIdentifier(0), ColumnType.Text)
            };

            Assert.DoesNotThrow(() => mappings.Add(new ColumnMapping(new ColumnNameIdentifier("name"), new ColumnOrdinalIdentifier(1), ColumnType.Text)));
        }
Exemplo n.º 12
0
        public void Add_MixOfNameAndOrdinal_NBiException()
        {
            var mappings = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnNameIdentifier("name"), ColumnType.Text)
            };

            Assert.Throws <NBiException>(() => mappings.Add(new ColumnMapping(new ColumnOrdinalIdentifier(1), ColumnType.Text)));
        }
Exemplo n.º 13
0
        private ColumnMappingCollection BuildColumnMapping(int count, int shift = 0)
        {
            var mappings = new ColumnMappingCollection();

            for (int i = 0; i < count; i++)
            {
                mappings.Add(new ColumnMapping(new ColumnOrdinalIdentifier(i + shift), new ColumnOrdinalIdentifier(i + shift), ColumnType.Text));
            }
            return(mappings);
        }
Exemplo n.º 14
0
        private ColumnMappingCollection BuildColumnMapping(int count, int shift = 0)
        {
            var mappings = new ColumnMappingCollection();

            for (int i = 0; i < count; i++)
            {
                mappings.Add(new ColumnMapping($"#{i}", $"#{i + shift}", ColumnType.Text));
            }
            return(mappings);
        }
Exemplo n.º 15
0
 protected virtual IEnumerable <IColumnDefinition> BuildMetadata(ColumnMappingCollection mappings, ColumnRole role, Func <ColumnMapping, IColumnIdentifier> identify)
 {
     foreach (var mapping in mappings ?? new ColumnMappingCollection())
     {
         yield return new Column()
                {
                    Identifier = identify.Invoke(mapping),
                    Role       = role,
                    Type       = mapping.Type,
                }
     }
     ;
 }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            string ConnectionString = @"Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = xe)));Persist Security Info=True;User ID=HR;Password=hr";

            try
            {
                var mappings = new ColumnMappingCollection();

                // Start defining the mappings between each property/column for a type
                mappings.RegisterType <Employee>()
                .MapProperty(x => x.EmployeeId).ToColumn("EMPLOYEE_ID")
                .MapProperty(x => x.Name).ToColumn("LAST_NAME")
                .MapProperty(x => x.HireDate).ToColumn("HIRE_DATE")
                .MapProperty(x => x.JobId).ToColumn("JOB_ID")
                .MapProperty(x => x.Email).ToColumn("EMAIL");
                mappings.RegisterWithDapper();


                using (var dbConn = new OracleConnection(ConnectionString))
                {
                    //Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;

                    dbConn.Open();
                    int id = 207;

                    var delQuery = @"delete employees where EMPLOYEE_ID=" + id;
                    dbConn.Execute(delQuery);

                    var insertQuery
                        = "insert into employees(EMPLOYEE_ID,LAST_NAME,HIRE_DATE,JOB_ID,EMAIL) values(207,'Sairam','15-APR-2018','IT_PROG','*****@*****.**')";

                    dbConn.Execute(insertQuery);

                    Console.WriteLine("**********");
                    Console.WriteLine("Before update");
                    Print(dbConn, id);

                    var updateQuery
                        = @"update employees set email='*****@*****.**' where EMPLOYEE_ID=" + id;
                    dbConn.Execute(updateQuery);

                    Console.WriteLine("**********");
                    Console.WriteLine("After update");
                    Print(dbConn, id);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 17
0
        public void Execute_DuplicatedKeyColumns_NoViolation()
        {
            var child     = BuildDataTable(new[] { "Key0", "Key1" }, new[] { "Foo", "Bar" }, new object[] { 0, 1 });
            var reference = BuildDataTable(new[] { "Key0", "Key1", "Key1" }, new[] { "Foo", "Bar", "Bar" }, new object[] { 1, 2, 3 });

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnOrdinalIdentifier(0), ColumnType.Text),
                new ColumnMapping(new ColumnOrdinalIdentifier(1), ColumnType.Text)
            };
            var referencer = new LookupExistsAnalyzer(mapping);
            var violations = referencer.Execute(child, reference);

            Assert.That(violations.Count(), Is.EqualTo(0));
        }
Exemplo n.º 18
0
        public void Execute_DuplicatedKeyColumnsOnBothSide_NoViolation()
        {
            var child  = BuildDataTable(new[] { "Key0", "Key1", "Key0" }, new[] { "Foo", "Bar", "Foo" }, new object[] { 0, 1, 2 });
            var parent = BuildDataTable(new[] { "Key0", "Key1", "Key1" }, new[] { "Foo", "Bar", "Bar" }, new object[] { 1, 2, 3 });

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping("#0", "#0", ColumnType.Text),
                new ColumnMapping("#1", "#1", ColumnType.Text)
            };
            var referencer = new ReferenceAnalyzer(mapping);
            var violations = referencer.Execute(child, parent);

            Assert.That(violations.Count(), Is.EqualTo(0));
        }
Exemplo n.º 19
0
        public void Execute_NamedColumns_NoViolation()
        {
            var child  = BuildDataTable(new[] { "Key0", "Key1", "Key0" }, new[] { "Foo", "Bar", "Foo" }, new object[] { 0, 1, 0 });
            var parent = BuildDataTable(new[] { "Key0", "Key1", "Key1" }, new[] { "Foo", "Bar", "Bar" }, new[] { "0.000", "1.0", "2" });

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping("zero", "zero", ColumnType.Text),
                new ColumnMapping("one", "one", ColumnType.Text),
                new ColumnMapping("two", "two", ColumnType.Numeric)
            };
            var referencer = new ReferenceAnalyzer(mapping);
            var violations = referencer.Execute(child, parent);

            Assert.That(violations.Count(), Is.EqualTo(0));
        }
Exemplo n.º 20
0
        public void Execute_MultipleKeysPermuteKeyColumnsOneMissingParent_OneViolation()
        {
            var child  = BuildDataTable(new[] { "Key0", "Key1", "Key2" }, new[] { "Foo", "Bar", "Fie" }, new object[] { 1, 2, 3 });
            var parent = BuildDataTable(new[] { "Key0", "Key1" }, new[] { "Foo", "Bar" }, new object[] { 0, 1 });

            parent.Columns[1].SetOrdinal(0);

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping("#0", "#1", ColumnType.Text),
                new ColumnMapping("#1", "#0", ColumnType.Text)
            };
            var referencer = new ReferenceAnalyzer(mapping);
            var violations = referencer.Execute(child, parent);

            Assert.That(violations.Count(), Is.EqualTo(1));
        }
Exemplo n.º 21
0
        public void Execute_MultipleKeysPermuteKeyColumnsOneMissingreference_OneViolation()
        {
            var child     = BuildDataTable(new[] { "Key0", "Key1", "Key2" }, new[] { "Foo", "Bar", "Fie" }, new object[] { 1, 2, 3 });
            var reference = BuildDataTable(new[] { "Key0", "Key1" }, new[] { "Foo", "Bar" }, new object[] { 0, 1 });

            reference.Columns[1].SetOrdinal(0);

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnOrdinalIdentifier(0), new ColumnOrdinalIdentifier(1), ColumnType.Text),
                new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text)
            };
            var referencer = new LookupExistsAnalyzer(mapping);
            var violations = referencer.Execute(child, reference);

            Assert.That(violations.Count(), Is.EqualTo(1));
        }
Exemplo n.º 22
0
        public void Execute_NamedColumnsShuffle_NoViolation()
        {
            var child     = BuildDataTable(new[] { "Key0", "Key1", "Key0" }, new[] { "Foo", "Bar", "Foo" }, new object[] { 0, 1, 0 });
            var reference = BuildDataTable(new[] { "Key0", "Key1", "Key1" }, new[] { "Foo", "Bar", "Bar" }, new[] { "0.000", "1.0", "2" });

            reference.Columns["two"].SetOrdinal(1);

            var mapping = new ColumnMappingCollection
            {
                new ColumnMapping(new ColumnNameIdentifier("zero"), ColumnType.Text),
                new ColumnMapping(new ColumnNameIdentifier("one"), ColumnType.Text),
                new ColumnMapping(new ColumnNameIdentifier("two"), ColumnType.Numeric)
            };
            var referencer = new LookupExistsAnalyzer(mapping);
            var violations = referencer.Execute(child, reference);

            Assert.That(violations.Count(), Is.EqualTo(0));
        }
Exemplo n.º 23
0
        protected override void SpecificBuild()
        {
            var ctrXml = ConstraintXml as LookupMatchesXml;

            ctrXml.ResultSet.Settings = ctrXml.Settings;


            var joinMappings      = new ColumnMappingCollection(BuildMappings(ctrXml.Join));
            var inclusionMappings = new ColumnMappingCollection(BuildMappings(ctrXml.Inclusion));

            var builder = new ResultSetServiceBuilder();

            builder.Setup(Helper.InstantiateResolver(ctrXml.ResultSet));
            builder.Setup(Helper.InstantiateAlterations(ctrXml.ResultSet));
            var service = builder.GetService();

            var ctr = new LookupMatchesConstraint(service);

            Constraint = ctr.Using(joinMappings, inclusionMappings);
        }
Exemplo n.º 24
0
        static DbMfg()
        {
            // Create a new mapping collection
            var mappings = new ColumnMappingCollection();

            // Defining the mappings between each property/column for a type
            mappings.RegisterType <AS400SewinQueueRoll>()
            .MapProperty(x => x.G2SCH).ToColumn("G2SCH#");

            mappings.RegisterType <CoaterScheduleRoll>()
            .MapProperty(x => x.SeqNo).ToColumn("Seq #")
            .MapProperty(x => x.SchedNo).ToColumn("Sched #")
            .MapProperty(x => x.CutLength).ToColumn("Cut Length")
            .MapProperty(x => x.Sewnin).ToColumn("Sewn-in")
            .MapProperty(x => x.FaceWt).ToColumn("Face Wt")
            .MapProperty(x => x.OrigSeq).ToColumn("Orig Seq");

            // Tell Dapper to use our custom mappings
            mappings.RegisterWithDapper();
        }
Exemplo n.º 25
0
        protected override void SpecificBuild()
        {
            var ctrXml = ConstraintXml as LookupMatchesXml;

            ctrXml.ResultSet.Settings = ctrXml.Settings;


            var joinMappings        = new ColumnMappingCollection(BuildMappings(ctrXml.Join));
            var inclusionMappings   = new ColumnMappingCollection(BuildMappings(ctrXml.Inclusion));
            var inclusionTolerances = BuildTolerances(ctrXml.Inclusion);

            var builder = new ResultSetServiceBuilder();
            var helper  = new ResultSetSystemHelper(ServiceLocator, SettingsXml.DefaultScope.Assert, Variables);

            builder.Setup(helper.InstantiateResolver(ctrXml.ResultSet));
            builder.Setup(helper.InstantiateAlterations(ctrXml.ResultSet));
            var service = builder.GetService();

            var ctr = new LookupMatchesConstraint(service);

            Constraint = ctr.Using(joinMappings, inclusionMappings, inclusionTolerances);
        }
Exemplo n.º 26
0
        public void Matches_ReferenceAnalyzer_CallToExecuteOnce()
        {
            var child = new ResultSet();

            child.Load("a;b;1");
            var childMock = new Mock <IResultSetService>();

            childMock.Setup(s => s.Execute())
            .Returns(child);
            var childService = childMock.Object;

            var parent = new ResultSet();

            parent.Load("a;b");
            var parentMock = new Mock <IResultSetService>();

            parentMock.Setup(s => s.Execute())
            .Returns(parent);
            var parentService = parentMock.Object;

            var mappings = new ColumnMappingCollection()
            {
                new ColumnMapping("#0", "#0", ColumnType.Text),
                new ColumnMapping("#1", "#1", ColumnType.Text),
            };


            var referenceExists = new ReferenceExistsConstraint(parentService);
            var analyzer        = new Mock <ReferenceAnalyzer>(mappings);

            analyzer.Setup(x => x.Execute(It.IsAny <ResultSet>(), It.IsAny <ResultSet>())).Returns(new ReferenceViolations());
            referenceExists.Engine = analyzer.Object;

            //Method under test
            referenceExists.Matches(childService);

            //Test conclusion
            analyzer.Verify(x => x.Execute(child, parent), Times.Once());
        }
Exemplo n.º 27
0
        public void Matches_ResultSetService_CallToExecuteOnce()
        {
            var child = new ResultSet();

            child.Load("a;b;1");
            var childMock = new Mock <IResultSetService>();

            childMock.Setup(s => s.Execute())
            .Returns(child);
            var childService = childMock.Object;

            var parent = new ResultSet();

            parent.Load("a;b");
            var parentMock = new Mock <IResultSetService>();

            parentMock.Setup(s => s.Execute())
            .Returns(parent);
            var parentService = parentMock.Object;

            var mappings = new ColumnMappingCollection()
            {
                new ColumnMapping("#0", "#0", ColumnType.Text),
                new ColumnMapping("#1", "#1", ColumnType.Text),
            };


            var referenceExists = new ReferenceExistsConstraint(parentService);

            referenceExists = referenceExists.Using(mappings);

            //Method under test
            referenceExists.Matches(childService);

            //Test conclusion
            childMock.Verify(s => s.Execute(), Times.Once());
            parentMock.Verify(s => s.Execute(), Times.Once());
        }
Exemplo n.º 28
0
        protected override void SpecificBuild()
        {
            var ctrXml = ConstraintXml as ReferenceExistsXml;

            ctrXml.ResultSet.Settings = ctrXml.Settings;

            var mappings = new ColumnMappingCollection();

            foreach (var mapping in ctrXml.Mappings)
            {
                mappings.Add(new ColumnMapping(mapping.Child, mapping.Parent, mapping.Type));
            }

            var builder = new ResultSetServiceBuilder();

            builder.Setup(Helper.InstantiateResolver(ctrXml.ResultSet));
            builder.Setup(Helper.InstantiateAlterations(ctrXml.ResultSet));
            var service = builder.GetService();

            var ctr = new ReferenceExistsConstraint(service);

            Constraint = ctr.Using(mappings);
        }
Exemplo n.º 29
0
 internal TableMapping()
 {
     this.columnMappings = new ColumnMappingCollection(this);
 }
Exemplo n.º 30
0
        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 rows = violations.Values.Where(x => x is LookupExistsViolationInformation)
                       .Cast <LookupExistsViolationInformation>()
                       .SelectMany(x => x.CandidateRows);

            sampler.Build(rows);

            var tableHelper = new StandardTableHelperMarkdown(rows, metadata, sampler);

            tableHelper.Render(container);
        }
Exemplo n.º 31
0
 public Form1()
 {
     InitializeComponent();
     _mapping = ColumnMapper.AutomapForType<Product>();
     //_mapping = ColumnMapper.ForType<Product>(x => x.Named("test").AtIndex(3));
 }
Exemplo n.º 32
0
 public KeyBuilder(KeyMapping mapping)
 {
     this.mapping = mapping;
     Columns = new ColumnMappingCollection(mapping, sharedColumnAttributes);
 }