예제 #1
0
        public void ShouldAppendScriptFromStringBuilder()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("DROP TABLE [table1]");
            builder.AppendLine("DROP TABLE [table2]");

            SqlScript script = new SqlScript();

            script.Append(builder);

            Assert.AreEqual(builder.Length, script.Length, "Lengths are no equals");
            Assert.AreEqual("DROP TABLE [table1]\r\nDROP TABLE [table2]\r\n", script.ToScript(),
                            "Script contents don't matchs");
        }
예제 #2
0
        public void ShouldScriptDropColumn()
        {
            SetupResult.For(templateManager.DropColumn).Return(@"DropColumn.vm");
            mocks.ReplayAll();

            ColumnStub column = table.AddStubbedColumn("LastName", "NVARCVHAR(50)");

            SqlScript script = scriptBuilder.Drop(column);
            string    sql    = script.ToScript();

            Console.WriteLine(sql);
            Assert.IsTrue(sql.Contains("IF EXISTS"), "Missing IF EXISTS");
            Assert.IsTrue(sql.Contains("ALTER TABLE [dbo].[Customer]"), "Missing ALTER TABLE");
            Assert.IsTrue(sql.Contains("DROP [LastName]"), "Missing DROP column");
        }
예제 #3
0
        public void ShouldScriptCreateTable()
        {
            SetupResult.For(templateManager.CreateTable).Return(@"CreateTable.vm");
            mocks.ReplayAll();

            table.AddStubbedColumn("Name", "NVARCHAR(50)");
            table.AddStubbedColumn("Dob", "DATETIME");

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

            Console.WriteLine(sql);
            Assert.IsTrue(sql.Contains("IF NOT EXISTS"), "Missing IF NOT EXISTS");
            Assert.IsTrue(sql.Contains("CREATE TABLE [dbo].[Customer]"));
        }
예제 #4
0
        public void ShouldScriptAddColumn()
        {
            SetupResult.For(templateManager.CreateColumn).Return(@"AddColumn.vm");
            mocks.ReplayAll();

            ColumnStub column = table.AddStubbedColumn("LastName", "NVARCHAR(50)");

            column.isNullable = false;

            SqlScript script = scriptBuilder.Create(column);
            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 [LastName] NVARCHAR(50) NOT NULL"), "Missing ADD column");
        }
예제 #5
0
        public void ShouldScriptCreateUniqueIndex()
        {
            SetupResult.For(templateManager.CreateIndex).Return(@"CreateIndex.vm");
            mocks.ReplayAll();

            ColumnStub column = table.AddStubbedColumn("LastName", "NVARCHAR(50)");
            IndexStub  index  = table.AddStubbedIndex(column, "IX_LastName");

            index.unique = true;

            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 UNIQUE NONCLUSTERED INDEX [IX_LastName]"),
                          "Missing CREATE NONCLUSTERED INDEX");
            Assert.IsTrue(sql.Contains("[dbo].[Customer]"), "Missing [dbo].[Customer]");
            Assert.IsTrue(sql.Contains("LastName"), "Missing LastName");
        }