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"); }
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"); }
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]")); }
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"); }
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"); }