Ejemplo n.º 1
0
        private void Test(bool[] rowsToKeep)
        {
            int count = rowsToKeep.Length;

            // Build an identity column
            NumberColumn <int> column = new NumberColumn <int>(-1);

            for (int i = 0; i < rowsToKeep.Length; ++i)
            {
                column[i] = i;
            }

            // Build a RowUpdater and fake mapping to temp to check those results
            TableStub  table   = new TableStub();
            RowUpdater updater = new RowUpdater(table, table);

            int[] rowsToTemp = Enumerable.Range(10, count).ToArray();

            // Request Garbage Collection
            GarbageCollector.Collect <int>(column, null, rowsToKeep, updater, rowsToTemp);

            // Verify correct values were kept
            StringBuilder expected      = new StringBuilder();
            int           expectedCount = 0;

            for (int i = 0; i < count; ++i)
            {
                if (rowsToKeep[i])
                {
                    expectedCount++;

                    if (expected.Length > 0)
                    {
                        expected.Append(", ");
                    }
                    expected.Append(i);
                }
            }

            Assert.Equal(expectedCount, column.Count);
            Assert.Equal(expected.ToString(), String.Join(", ", column.OrderBy((i) => i)));

            // Verify rows removed are reported in the correct indices in temp or swapped in original column
            RowStub stub = new RowStub(table, 0);

            for (int i = 0; i < count; ++i)
            {
                stub.Index = i;
                updater.Update(stub);

                if (!rowsToKeep[i])
                {
                    Assert.Equal(10 + i, stub.Index);
                }
                else
                {
                    Assert.Equal(i, column[stub.Index]);
                }
            }
        }
Ejemplo n.º 2
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.º 3
0
        public void SetUp()
        {
            table = new TableStub(new DatabaseStub("Test"), "Customers");
            table.AddStubbedColumn("CustomerID", "INT");
            table.AddStubbedColumn("FirstName", "NVARCHAR(50)");
            table.AddStubbedColumn("DateOfBirth", "DATETIME");

            tblData = new TableData();
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            templateDir = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\Sneal.SqlMigration\Templates";

            mocks           = new MockRepository();
            templateManager = mocks.DynamicMock <ISqlTemplateManager>();

            SetupResult.For(templateManager.TemplateDirectory).Return(templateDir);
            mocks.Replay(templateManager);
            scriptBuilder = new SqlServerScriptBuilder(templateManager);
            mocks.BackToRecord(templateManager);

            db    = new DatabaseStub("DB");
            table = new TableStub(db, "Customer");
        }
Ejemplo n.º 8
0
        internal static DatabaseStub CreateStubbedSourceDB()
        {
            DatabaseStub db = new DatabaseStub("AdeventureWorks");

            TableStub table = new TableStub(db, "Customer");

            table.columns.Add(new ColumnStub(table, "CustomerID", "INT"));
            table.columns.Add(new ColumnStub(table, "FirstName", "NVARCHAR(50)"));
            table.columns.Add(new ColumnStub(table, "LastName", "NVARCHAR(50)"));
            table.columns.Add(new ColumnStub(table, "Email", "NVARCHAR(50)"));
            table.columns.Add(new ColumnStub(table, "PrimaryEmail", "NVARCHAR(50)"));
            table.columns.Add(new ColumnStub(table, "CustomerTypeID", "INT"));

            return(db);
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            table = new TableStub(new DatabaseStub("Test"), "Customers");
            ColumnStub col1 = table.AddStubbedColumn("CustomerID", "INT");

            col1.DataType = (int)OleDbType.Integer;
            ColumnStub col2 = table.AddStubbedColumn("FirstName", "NVARCHAR(50)");

            col2.DataType = (int)OleDbType.VarWChar;
            ColumnStub col3 = table.AddStubbedColumn("DateOfBirth", "DATETIME");

            col3.DataType = (int)OleDbType.Date;

            gen = new SqlServerXsdGenerator();
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        public void ShouldScriptCreateIndex()
        {
            SetupResult.For(templateManager.CreateIndex).Return(@"CreateIndex.vm");
            mocks.ReplayAll();

            DatabaseStub db     = new DatabaseStub("DB");
            TableStub    table  = new TableStub(db, "Customer");
            ColumnStub   column = table.AddStubbedColumn("LastName", "NVARCHAR(50)");
            IndexStub    index  = table.AddStubbedIndex(column, "IX_LastName");

            index.unique = false;

            SqlScript script = scriptBuilder.Create(index);
            string    sql    = script.ToScript();

            Console.WriteLine(sql);
            Assert.IsTrue(sql.Contains("IF NOT EXISTS"), "Missing IF NOT EXISTS");
            Assert.IsTrue(sql.Contains("CREATE NONCLUSTERED INDEX [IX_LastName]"), "Missing CREATE NONCLUSTERED INDEX");
            Assert.IsTrue(sql.Contains("[dbo].[Customer]"), "Missing [dbo].[Customer]");
            Assert.IsTrue(sql.Contains("LastName"), "Missing LastName");
        }