Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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));
        }