public void The_Removed_Column_And_The_Changed_Key_Are_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].RemoveKey(db2.Tables[0].Keys[0]);
                db2.Tables[0].RemoveIndex(db2.Tables[0].Indexes[0]);
                db2.Tables[0].RemoveColumn(db2.Tables[0].Columns[0]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);

                Assert.That(result.IndexOperations, Has.Count(1), "There should be one Index operation");
                var indexOp = result.IndexOperations.ElementAt(0);

                Assert.That(indexOp, Is.TypeOf(typeof(IndexRemovalOperation)));
                Assert.That(indexOp.Object, Is.SameAs(db1.Tables[0].Indexes[0]), "Removed index should be equal to PK_Table1 from db1");

                Assert.That(result.KeyOperations, Has.Count(1), "There should be one Key operation");
                var keyOp = result.KeyOperations.ElementAt(0);

                Assert.That(keyOp, Is.TypeOf(typeof(KeyRemovalOperation)));
                Assert.That(keyOp.Object, Is.SameAs(db1.Tables[0].Keys[0]), "Removed Key should be equal to PK_Table1 from db1");

                Assert.That(result.ColumnOperations, Has.Count(1), "There should be one Column operation");
                IMergeOperation <IColumn> columnOp = result.ColumnOperations.ElementAt(0);

                Assert.That(columnOp, Is.TypeOf(typeof(ColumnRemovalOperation)));
                Assert.That(columnOp.Object, Is.SameAs(db1.Tables[0].Columns[0]), "Removed column should be equal to Table1.Column1 from db1");
            }
            public void The_Removed_Columns_Are_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();

                db1.Tables[0].AddColumn(new Column("aaaaaa"));
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].RemoveColumn(db1.Tables[0].Columns[2]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);

                Assert.That(result.ColumnOperations, Is.Not.Empty);
                Assert.That(result.ColumnOperations, Has.Count(2));

                IMergeOperation <IColumn> op = result.ColumnOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Columns[2]));
                Assert.That(op, Is.TypeOf(typeof(ColumnRemovalOperation)));

                op = result.ColumnOperations.ElementAt(1);
                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Columns[3]));
                Assert.That(op, Is.TypeOf(typeof(ColumnRemovalOperation)));
            }
Пример #3
0
            public void The_Original_Index_Should_Be_Modified()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                IIndex originalIndex = db1.Tables[0].Indexes[0];

                originalIndex.Description = "old description";

                IIndex newIndex = new Index(originalIndex.Name);

                newIndex.Parent = new Table("Table1");
                newIndex.Parent.AddColumn(new Column("Column2"));
                newIndex.Description = "new description";
                newIndex.AddColumn("Column2");

                IndexChangeOperation op = new IndexChangeOperation(db1.Tables[0].Indexes[0], newIndex);

                op.RunOperation();
                op.RunSecondStep();

                IIndex index = db1.Tables[0].Indexes[0];

                Assert.That(db1.Tables[0].Indexes, Has.Count(1), "No new indexes should have been added");
                Assert.That(index, Is.SameAs(originalIndex), "Index object should still be the same");
                Assert.That(index.Description, Is.EqualTo("old description"));
                Assert.That(index.Columns, Has.Count(1));
                Assert.That(index.Columns[0].Name, Is.EqualTo("Column2"));
                Assert.That(index.Columns[0], Is.Not.SameAs(newIndex.Columns[0]));
                Assert.That(index.Columns[0], Is.SameAs(db1.Tables[0].Columns[1]), "The new Index should reference existing columns");
                Assert.That(index.Parent, Is.SameAs(db1.Tables[0]), "The new Index's parent should be Table1 in the existing database");
            }
            public void The_Removed_Keys_Are_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();

                // This key doesn't exist in the second db, so is effectively "removed"
                db1.Tables[0].AddKey(new Key("aaaaaa"));
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].RemoveKey(db2.Tables[0].Keys[0]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.KeyOperations, Has.Count(2));

                IMergeOperation <IKey> op = result.KeyOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Keys[0]));
                Assert.That(op, Is.TypeOf(typeof(KeyRemovalOperation)));

                op = result.KeyOperations.ElementAt(1);
                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Keys[1]));
                Assert.That(op, Is.TypeOf(typeof(KeyRemovalOperation)));
            }
Пример #5
0
            public void The_Original_Primary_Key_Should_Be_Modified()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                IKey originalKey = db1.Tables[0].Keys[0];

                originalKey.Description = "old description";

                IKey newKey = new Key(originalKey.Name);

                newKey.Parent = new Table("Table1");
                newKey.Parent.AddColumn(new Column("Column2"));
                newKey.Description = "new description";
                newKey.AddColumn("Column2");

                KeyChangeOperation op = new KeyChangeOperation(db1.Tables[0].Keys[0], newKey);

                op.RunOperation();
                op.RunSecondStep();

                IKey key = db1.Tables[0].Keys[0];

                Assert.That(db1.Tables[0].Keys, Has.Count(1));
                Assert.That(key, Is.SameAs(originalKey), "Key object should still be the same");
                Assert.That(key.Description, Is.EqualTo("old description"), "Should not change user set properties.");
                Assert.That(key.ReferencedKey, Is.Null);
                Assert.That(key.Columns, Has.Count(1));
                Assert.That(key.Columns[0].Name, Is.EqualTo("Column2"));
                Assert.That(key.Columns[0], Is.Not.SameAs(newKey.Columns[0]));
                Assert.That(key.Columns[0], Is.SameAs(db1.Tables[0].Columns[1]), "The new key should reference existing columns");
                Assert.That(key.Parent, Is.SameAs(db1.Tables[0]), "The new key's parent should be Table1 in the existing database");
            }
            public void The_New_Tables_Are_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.AddTable(new Table("Table2"));
                db2.AddTable(new Table("aaaaaaa"));

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.ColumnOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);

                Assert.That(result.TableOperations, Has.Count(2));

                var op = (TableAdditionOperation)result.TableOperations.ElementAt(0);

                Assert.That(op, Is.Not.Null);
                Assert.That(op.Object, Is.SameAs(db2.Tables[1]));
                Assert.That(op.Database, Is.SameAs(db1));

                op = (TableAdditionOperation)result.TableOperations.ElementAt(1);
                Assert.That(op, Is.Not.Null);
                Assert.That(op.Object, Is.SameAs(db2.Tables[2]));
                Assert.That(op.Database, Is.SameAs(db1));
            }
            public void The_New_Column_And_The_Changed_Key_Are_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].AddColumn(new Column("Column4")
                {
                    InPrimaryKey = true
                });
                db2.Tables[0].Keys[0].AddColumn("Column4");
                db2.Tables[0].Indexes[0].AddColumn("Column4");

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);

                Assert.That(result.IndexOperations, Has.Count(1));
                var indexOp = result.IndexOperations.ElementAt(0);

                Assert.That(indexOp, Is.TypeOf(typeof(IndexChangeOperation)));
                Assert.That(indexOp.Object, Is.SameAs(db1.Tables[0].Indexes[0]), "Changed index should be equal to PK_Table1 from db1");

                Assert.That(result.KeyOperations, Has.Count(1));
                var keyOp = result.KeyOperations.ElementAt(0);

                Assert.That(keyOp, Is.TypeOf(typeof(KeyChangeOperation)));
                Assert.That(keyOp.Object, Is.SameAs(db1.Tables[0].Keys[0]), "Changed Key should be equal to PK_Table1 from db1");

                Assert.That(result.ColumnOperations, Has.Count(1));
                IMergeOperation <IColumn> columnOp = result.ColumnOperations.ElementAt(0);

                Assert.That(columnOp, Is.TypeOf(typeof(ColumnAdditionOperation)));
                Assert.That(columnOp.Object, Is.SameAs(db2.Tables[0].Columns[3]), "Added column should be equal to Table1.Column4 from db2");
            }
Пример #8
0
            public void Setup()
            {
                db = TestDatabaseLoader.TestDatabase();

                var t2 = new Table("Table2");

                db.AddTable(t2);
                t2.AddColumn(new Column("Column1")
                {
                    InPrimaryKey = true, Datatype = "int", OrdinalPosition = 0, Size = 4
                });
                t2.AddColumn(new Column("Column2")
                {
                    Datatype = "nvarchar", OrdinalPosition = 1, Size = 100
                });
                t2.AddColumn(new Column("Column3")
                {
                    Datatype = "datetime", OrdinalPosition = 2, Size = 8
                });

                t2.AddIndex(new Index("PK_Table2")
                {
                    IsUnique = true, Datatype = DatabaseIndexType.PrimaryKey
                }).AddColumn("Column1");
                t2.AddKey(new Key("PK_Table2")
                {
                    Keytype = DatabaseKeyType.Primary
                }).AddColumn("Column1").AddColumn("Column2");

                t2.CreateRelationshipTo(db.Tables[0]);
            }
Пример #9
0
            public void The_Original_Database_Should_Not_Contain_The_Removed_Index()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                IndexRemovalOperation op = new IndexRemovalOperation(db1.Tables[0].Indexes[0]);

                op.RunOperation();

                Assert.That(db1.Tables[0].Indexes, Is.Empty);
            }
Пример #10
0
            public void The_Index_Is_Marked_As_User_Defined()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                IndexRemovalOperation op = new IndexRemovalOperation(db1.Tables[0].Indexes[0]);

                op.NotApplied();

                Assert.That(db1.Tables[0].Indexes, Has.Count(1));
                Assert.That(db1.Tables[0].Indexes[0].IsUserDefined, Is.True);
            }
Пример #11
0
            public void The_Key_Should_Be_Marked_As_User_Defined()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                KeyRemovalOperation op = new KeyRemovalOperation(db1.Tables[0].Keys[0]);

                op.NotApplied();

                Assert.That(db1.Tables[0].Keys, Has.Count(1));
                Assert.That(db1.Tables[0].Keys[0].IsUserDefined, Is.True);
            }
        public void The_ResultSet_Has_Nothing_in_It()
        {
            Database db1 = TestDatabaseLoader.TestDatabase();
            Database db2 = TestDatabaseLoader.TestDatabase();

            DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

            Assert.That(result.TableOperations, Is.Empty);
            Assert.That(result.ColumnOperations, Is.Empty);
            Assert.That(result.IndexOperations, Is.Empty);
            Assert.That(result.KeyOperations, Is.Empty);
        }
Пример #13
0
            public void The_Original_Database_Should_Contain_A_Copy_Of_The_New_Column()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                Column newCol = new Column("Column4");
                ColumnAdditionOperation op = new ColumnAdditionOperation(db1.Tables[0], newCol);

                op.RunOperation();

                Assert.That(db1.Tables[0].Columns, Has.Count(4));
                Assert.That(db1.Tables[0].Columns[3].Name, Is.EqualTo(newCol.Name));
                Assert.That(db1.Tables[0].Columns[3], Is.Not.SameAs(newCol), "The added column should be a copy, not the original object.");
            }
Пример #14
0
            public void The_Original_Database_Should_Not_Contain_The_Removed_Column()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                IColumn oldColumn         = db1.Tables[0].Columns[0];
                ColumnRemovalOperation op = new ColumnRemovalOperation(db1.Tables[0].Columns[0]);

                op.RunOperation();

                Assert.That(db1.Tables[0].Columns, Has.Count(2));
                Assert.That(db1.Tables[0].Columns.Contains(oldColumn), Is.False);
                Assert.That(db1.Tables[0].Keys[0].Columns, Has.Count(1), "The column should have been removed from the primary key");
                Assert.That(db1.Tables[0].Indexes[0].Columns, Is.Empty, "The column should have been removed from the unique index");
            }
Пример #15
0
            public void The_Original_Column_Should_Be_Modified()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                IColumn originalColumn = db1.Tables[0].Columns[2];
                IColumn newColumn      = originalColumn.Clone();

                newColumn.Datatype = "some datatype";
                ColumnChangeOperation op = new ColumnChangeOperation(db1.Tables[0].Columns[2], newColumn);

                op.RunOperation();

                Assert.That(db1.Tables[0].Columns, Has.Count(3));
                Assert.That(db1.Tables[0].Columns[2], Is.SameAs(originalColumn), "Column object should still be the same");
                Assert.That(db1.Tables[0].Columns[2].Datatype, Is.EqualTo("some datatype"));
            }
            public void The_Removed_Table_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.RemoveTable(db2.Tables[0]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.ColumnOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);

                Assert.That(result.TableOperations, Has.Count(1));
                var op = (TableRemovalOperation)result.TableOperations.ElementAt(0);

                Assert.That(op, Is.Not.Null);
                Assert.That(op.Object, Is.SameAs(db1.Tables[0]));
            }
            public void The_Removed_Index_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].RemoveIndex(db2.Tables[0].Indexes[0]);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.IndexOperations, Has.Count(1));
                IMergeOperation <IIndex> op = result.IndexOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Indexes[0]));
                Assert.That(op, Is.TypeOf(typeof(IndexRemovalOperation)));
            }
            public void The_New_Key_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].AddKey(new Key("PK_Table1_1"));

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.KeyOperations, Has.Count(1));
                IMergeOperation <IKey> op = result.KeyOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db2.Tables[0].Keys[1]));
                Assert.That(op, Is.TypeOf(typeof(KeyAdditionOperation)));
            }
Пример #19
0
        internal static Database GetDb()
        {
            var   db     = TestDatabaseLoader.TestDatabase();
            Table table2 = new Table("Table2");

            table2.AddColumn(new Column("Column1"));
            table2.AddColumn(new Column("Column2"));
            table2.AddColumn(new Column("Column3"));
            Key foreignKey = new Key("FK_Table2", DatabaseKeyType.Foreign);

            foreignKey.Parent        = table2;
            foreignKey.ReferencedKey = db.Tables[0].Keys[0];
            foreignKey.AddColumn("Column1");
            foreignKey.AddColumn("Column2");
            table2.AddKey(foreignKey);
            db.AddTable(table2);

            new DatabaseProcessor().CreateRelationships(db);
            return(db);
        }
            public void The_Changed_Key_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();

                db1.Tables[0].Keys[0].UID = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].Keys[0].Keytype = DatabaseKeyType.None;
                db2.Tables[0].Keys[0].UID     = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.TableOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.ColumnOperations, Is.Empty);

                Assert.That(result.KeyOperations, Has.Count(1));
                IMergeOperation <IKey> op = result.KeyOperations.ElementAt(0);

                Assert.That(op.Object, Is.SameAs(db1.Tables[0].Keys[0]));
                Assert.That(op, Is.TypeOf(typeof(KeyChangeOperation)));
            }
Пример #21
0
            public void The_Original_Database_Should_Contain_A_Copy_Of_The_New_Index()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                // Setup new key information
                Table parentTable = new Table("Table1");

                parentTable.AddColumn(new Column("Column3"));
                Index newIndex = new Index("UQ_Column3");

                newIndex.Parent = parentTable;
                newIndex.AddColumn("Column3");

                IndexAdditionOperation op = new IndexAdditionOperation(db1.Tables[0], newIndex);

                op.RunOperation();
                op.RunSecondStep();

                Assert.That(db1.Tables[0].Indexes, Has.Count(2));
                Assert.That(db1.Tables[0].Indexes[1].Name, Is.EqualTo(newIndex.Name));
                Assert.That(db1.Tables[0].Indexes[1], Is.Not.SameAs(newIndex), "The added Index should be a copy, not the original object.");
                Assert.That(db1.Tables[0].Indexes[1].Columns[0], Is.SameAs(db1.Tables[0].Columns[2]), "The new Index should reference existing columns, not the new ones");
                Assert.That(db1.Tables[0].Indexes[1].Parent, Is.SameAs(db1.Tables[0]), "The new Index's parent should be Table1 in the existing database");
            }
Пример #22
0
            public void The_Original_Database_Should_Contain_A_Copy_Of_The_New_Table()
            {
                var db1 = TestDatabaseLoader.TestDatabase();

                Table  newTable  = new Table("Table2");
                Column newColumn = new Column("Column1");
                Key    newKey    = new Key("PrimaryKey");
                Index  newIndex  = new Index("Index1");

                newTable.AddColumn(newColumn);
                newTable.AddKey(newKey);
                newTable.AddIndex(newIndex);

                TableAdditionOperation op = new TableAdditionOperation(db1, newTable);

                op.RunOperation();

                Assert.That(db1.Tables, Has.Count(2));
                Assert.That(db1.Tables[1].Name, Is.EqualTo(newTable.Name));
                Assert.That(db1.Tables[1], Is.Not.SameAs(newTable), "The added table should be a copy, not the original object.");
                Assert.That(db1.Tables[1].Columns[0], Is.EqualTo(newColumn));
                Assert.That(db1.Tables[1].Keys[0], Is.EqualTo(newKey));
                Assert.That(db1.Tables[1].Indexes[0], Is.EqualTo(newIndex));
            }
            public void The_Changed_Table_Is_In_The_ResultSet()
            {
                Database db1 = TestDatabaseLoader.TestDatabase();

                db1.Tables[0].UID = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

                Database db2 = TestDatabaseLoader.TestDatabase();

                db2.Tables[0].UID  = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
                db2.Tables[0].Name = "SomethingElse";

                DatabaseMergeResult result = new DatabaseProcessor().MergeDatabases(db1, db2);

                Assert.That(result.ColumnOperations, Is.Empty);
                Assert.That(result.IndexOperations, Is.Empty);
                Assert.That(result.KeyOperations, Is.Empty);

                Assert.That(result.TableOperations, Has.Count(1));

                var op = (TableChangeOperation)result.TableOperations.ElementAt(0);

                Assert.That(op, Is.Not.Null);
                Assert.That(op.Object, Is.SameAs(db1.Tables[0]));
            }