public void ShouldScriptAddForeignKey() { SetupResult.For(templateManager.CreateForeignKey).Return(@"CreateForeignKey.vm"); mocks.ReplayAll(); TableStub fkTable = db.AddStubbedTable("Customer"); ColumnStub fkCol = fkTable.AddStubbedColumn("BillingID", "INT"); ForeignKeyStub fk = fkCol.AddForeignKeyStub("FK_Customer_BillingID"); TableStub pkTable = db.AddStubbedTable("Billing"); ColumnStub pkCol = pkTable.AddStubbedColumn("BillingID", "INT"); fk.primaryColumns.Add(pkCol); fk.primaryTable = pkTable; SqlScript script = scriptBuilder.Create(fk); string sql = script.ToScript(); Console.WriteLine(sql); Assert.IsTrue(sql.Contains("IF NOT EXISTS"), "Missing IF NOT EXISTS"); Assert.IsTrue(sql.Contains("ALTER TABLE [dbo].[Customer]"), "Missing ALTER TABLE"); Assert.IsTrue(sql.Contains("ADD CONSTRAINT"), "Missing ADD CONSTRAINT"); Assert.IsTrue(sql.Contains("FK_Customer_BillingID"), "Missing FK_Customer_BillingID"); Assert.IsTrue(sql.Contains("REFERENCES [dbo].[Billing]"), "Missing REFERENCES Billing"); }
public void ShouldReturnTableDoesNotExist() { DatabaseStub srcDB = new DatabaseStub("SourceDB"); TableStub srcTable = srcDB.AddStubbedTable("Table1"); DatabaseStub targetDB = new DatabaseStub("TargetDB"); Assert.IsFalse(comparer.Table(srcTable).ExistsIn(targetDB)); }
public void ShouldReturnColumnDoesNotExistWhenTableDoesNotExist() { DatabaseStub srcDB = new DatabaseStub("SourceDB"); TableStub srcTable = srcDB.AddStubbedTable("Table1"); srcTable.AddStubbedColumn("Col1", "INT"); DatabaseStub targetDB = new DatabaseStub("TargetDB"); Assert.IsFalse(comparer.Column(srcTable.Columns[0]).ExistsIn(targetDB)); }
public void ShouldReturnForeignKeyDoesNotExistWhenTableDoesNotExist() { DatabaseStub srcDB = new DatabaseStub("SourceDB"); TableStub srcTable = srcDB.AddStubbedTable("Table1"); ColumnStub srcCol = srcTable.AddStubbedColumn("Col1", "INT"); srcCol.AddForeignKeyStub("FK1"); DatabaseStub targetDB = new DatabaseStub("TargetDB"); Assert.IsFalse(comparer.ForeignKey(srcTable.ForeignKeys[0]).ExistsIn(targetDB)); }
public void ShouldReturnIndexExists() { DatabaseStub srcDB = new DatabaseStub("SourceDB"); TableStub srcTable = srcDB.AddStubbedTable("Table1"); ColumnStub srcCol = srcTable.AddStubbedColumn("Col1", "INT"); srcTable.AddStubbedIndex(srcCol, "IX_COL1"); DatabaseStub targetDB = new DatabaseStub("TargetDB"); TableStub targetTable = targetDB.AddStubbedTable("Table1"); ColumnStub targetCol = targetTable.AddStubbedColumn("Col1", "INT"); targetTable.AddStubbedIndex(targetCol, "IX_COL1"); Assert.IsTrue(comparer.Index(srcTable.Indexes[0]).ExistsIn(targetDB)); }