public void CollateScriptWithSchemaCheckTest_NeedsSchema() { ObjectScriptHelper target = new ObjectScriptHelper(new ConnectionData()); StringCollection coll = new StringCollection(); coll.Add(@"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[MyObject]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[MyObject]( [MyObjectID] [int] IDENTITY(1,1) NOT NULL " ); string schema = "dbo"; StringBuilder sb = new StringBuilder(); target.CollateScriptWithSchemaCheck(coll, schema, ref sb); Assert.IsTrue(sb.ToString().IndexOf("OBJECT_ID(N'[dbo].[MyObject]')") > -1); }
public void CollateScriptWithSchemaCheckTest_MultipleGoodWithSchema() { ObjectScriptHelper target = new ObjectScriptHelper(new ConnectionData()); StringCollection coll = new StringCollection(); coll.Add(@"IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MyObject_Fk1]') AND parent_object_id = OBJECT_ID(N'[dbo].[MyObject]')) ALTER TABLE [dbo].[MyObject] WITH CHECK ADD CONSTRAINT [FK_MyObject_Fk1] FOREIGN KEY([MyObjectType]) REFERENCES [MyObjectType] ([MyObjectTypeID])"); string expected = String.Format(@"{0} GO ", coll[0]); string schema = "dbo"; StringBuilder sb = new StringBuilder(); target.CollateScriptWithSchemaCheck(coll, schema, ref sb); Assert.AreEqual(expected, sb.ToString()); }
public void CollateScriptWithSchemaCheckTest_HasObjectIdButNothingToDo() { ObjectScriptHelper target = new ObjectScriptHelper(new ConnectionData()); StringCollection coll = new StringCollection(); coll.Add(@"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyObject]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[MyObject]( [MyObjectID] [int] IDENTITY(1,1) NOT NULL " ); string expected = String.Format(@"{0} GO ", coll[0]); string schema = "dbo"; StringBuilder sb = new StringBuilder(); target.CollateScriptWithSchemaCheck(coll, schema, ref sb); Assert.AreEqual(expected, sb.ToString()); }
public void CollateScriptWithSchemaCheckTest_NothingToDo() { ObjectScriptHelper target = new ObjectScriptHelper(new ConnectionData()); StringCollection coll = new StringCollection(); coll.Add("This does not start with IF NOT EXISTS"); coll.Add("Neither does this"); string expected = String.Format(@"{0} GO {1} GO ", coll[0], coll[1]); string schema = "dbo"; StringBuilder sb = new StringBuilder(); target.CollateScriptWithSchemaCheck(coll, schema, ref sb); Assert.AreEqual(expected, sb.ToString()); }