Ejemplo n.º 1
0
        public void MapTable()
        {
            var extractColumns = new ExtractColumn(src, dest, rules);
            extractColumns.PerformRefactor();

            extractAssociation = new ExtractAssociation(src, dest, rules);
            extractAssociation.PerformRefactor();

            var mapper = new RecordMapper(
                rules,
                extractColumns.ForeignKeyResolver);

            InsertMappedFields(mapper);
        }
        public void Test_PerformRefactor_ExtractAssociation_Inserts_Into_Association_Table()
        {
            // arrange
            const int desttablename_id = 66;
            const int extracttable_id = 55;
            var extractAssocation = new ExtractAssociation(this.src.Object, this.dest.Object, this.rules.Object);
            var record = new Dictionary<string, object> {
                {"badField1", "value1"},
                {"badField2", "value2"}};
            this.dest.Setup(x => x.GetIdLastInsert()).Returns(extracttable_id);

            // act
            var result = extractAssocation.PerformRefactor();
            extractAssocation.InsertAssociationInserts(record, desttablename_id);

            // assert
            this.dest.Verify(x => x.InsertRecord("DestTableNameToExtractedTable",
                new Dictionary<string, object> {
                    {"desttablename_id", desttablename_id},
                    {"extractedtable_id", extracttable_id}}));
        }
        public void Test_PerformRefactor_ExtractAssociation_Inserts_Into_Extracted_Table()
        {
            // arrange
            var destQueue = new Queue<Dictionary<string, object>>();
            this.dest.Setup(x => x.InsertRecord(FirstExtractedTable, It.IsAny<Dictionary<string, object>>()))
                .Returns(1)
                .Callback((string t, Dictionary<string, object> record) => destQueue.Enqueue(record));
            this.dest.Setup(x => x.InsertRecord(SecondExtractedTable, It.IsAny<Dictionary<string, object>>()))
                .Returns(1)
                .Callback((string t, Dictionary<string, object> record) => destQueue.Enqueue(record));

            var extractAssociation = new ExtractAssociation(this.src.Object, this.dest.Object, this.rules.Object);

            // act
            var result = extractAssociation.PerformRefactor();

            // assert
            this.dest.Verify(x => x.InsertRecord(FirstExtractedTable, new Dictionary<string, object> { { "name", "value1" } }));
            this.dest.Verify(x => x.InsertRecord(FirstExtractedTable, new Dictionary<string, object> { { "name", "value2" } }));
            this.dest.Verify(x => x.InsertRecord(FirstExtractedTable, new Dictionary<string, object> { { "name", "value3" } }));
            this.dest.Verify(x => x.InsertRecord(SecondExtractedTable, new Dictionary<string, object> { { "name", "somethingvalue1" } }));
            this.dest.Verify(x => x.InsertRecord(SecondExtractedTable, new Dictionary<string, object> { { "name", "somethingvalue2" } }));
            this.dest.Verify(x => x.InsertRecord(SecondExtractedTable, new Dictionary<string, object> { { "name", "somethingvalue3" } }));
            this.dest.Verify(x => x.InsertRecord(SecondExtractedTable, new Dictionary<string, object> { { "name", "somethingelse2" } }));
            Assert.AreEqual(7, destQueue.Count);
            Assert.AreEqual(7, result);
        }
        public void Test_PerformRefactor_Creates_ExtractedAssociation()
        {
            // arrange
            var previous = "value1";
            this.dest.Setup(x => x.InsertRecord(FirstExtractedTable, It.IsAny<Dictionary<string, object>>()))
                .Returns(1)
                .Callback((string table, Dictionary<string, object> record) => previous = record["name"].ToString());
            this.dest.Setup(x => x.InsertRecord(SecondExtractedTable, It.IsAny<Dictionary<string, object>>()))
                .Returns(1)
                .Callback((string table, Dictionary<string, object> record) => previous = record["name"].ToString());

            var ids = new Dictionary<string, int> {
                {"value1", 555},
                {"value2", 777},
                {"value3", 888},
                {"somethingvalue1", 123},
                {"somethingvalue2", 321},
                {"somethingvalue3", 322},
                {"somethingelse2", 223}};

            this.dest.Setup(x => x.GetIdLastInsert())
                .Returns(() => ids[previous]);

            var extractAssocation = new ExtractAssociation(this.src.Object, this.dest.Object, this.rules.Object);

            // act
            var result = extractAssocation.PerformRefactor();

            // assert
            var extractedAssocation = extractAssocation.ExtractedAssociation;
            Assert.IsNotNull(extractedAssocation);

            var firstValues = new [] {"value1", "value2", "value3"};
            var secondValues = new [] {"somethingvalue1", "somethingvalue2", "somethingvalue3", "somethingelse2"};

            foreach (var value in firstValues)
                Assert.AreEqual(ids[value], extractedAssocation.GetIdFromField(FirstExtractedTable, value));

            foreach (var value in secondValues)
                Assert.AreEqual(ids[value], extractedAssocation.GetIdFromField(SecondExtractedTable, value));
        }