public bool RunCompare(DatabaseSchema schema1, DatabaseSchema schema2) { var comparer = new CompareSchemas(schema1, schema2); string txt; try { txt = comparer.Execute(); } catch (Exception exception) { Message = @"An error occurred while creating the script.\n" + exception.Message; return false; } if (string.IsNullOrEmpty(txt)) { Message = "No differences found"; } else { using (var scriptForm = new ScriptForm(txt)) { scriptForm.ShowDialog(); } } return true; }
public void WhenSecondSchemaIsEmptyThenEverythingIsDropped() { //arrange var schema1 = TestHelper.GetNorthwindReader().ReadAll(); var schema2 = new DatabaseSchema(null, null); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.AreNotEqual(string.Empty, script); if (schema1.Tables.Any()) { Assert.IsTrue(script.Contains("DROP TABLE")); } if (schema1.Views.Any()) { Assert.IsTrue(script.Contains("DROP VIEW")); } if (schema1.StoredProcedures.Any()) { Assert.IsTrue(script.Contains("DROP PROCEDURE")); } }
public void GivenIdenticalSchemas() { //arrange DatabaseSchema schema1 = CreateSchema(); DatabaseSchema schema2 = CreateSchema(); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.AreEqual(string.Empty, script); }
public void GivenDroppedTable() { //arrange DatabaseSchema schema1 = CreateSchema(); schema1.Tables.Add(CreateProductsTable()); DatabaseSchema schema2 = CreateSchema(); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.IsTrue(script.Contains("DROP TABLE [Products]")); }
public void GivenAddedColumn() { //arrange DatabaseSchema schema1 = CreateSchema(); var productsTable = CreateProductsTable(); schema1.Tables.Add(productsTable); DatabaseSchema schema2 = CreateSchema(); var productsTable2 = CreateProductsTable(); schema2.Tables.Add(productsTable2); var nameColumn = new DatabaseColumn { Name = "Name", DbDataType = "NVARCHAR", Length = 10, Nullable = false }; productsTable2.Columns.Add(nameColumn); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.IsTrue(script.Contains("ADD [Name]")); }
public void Given2DatabasesThenDifferencesFound() { //arrange CreateDatabases(); //act var dsr1 = new DatabaseReader("Data Source=" + Db1Sqlite + ";Version=3;", SqlType.SQLite); var schema1 = dsr1.ReadAll(); var dsr2 = new DatabaseReader("Data Source=" + Db2Sqlite + ";Version=3;", SqlType.SQLite); var schema2 = dsr2.ReadAll(); var comparison = new CompareSchemas(schema1, schema2); var result = comparison.Execute(); //assert //script should look like this... //-- ADDED TABLE Products COLUMN Cost //ALTER TABLE [Products] ADD [Cost] NUMERIC DEFAULT 0 NOT NULL; //-- Products from [Name] TEXT NOT NULL to [Name] TEXT NULL //-- TODO: change manually (no ALTER COLUMN) Assert.IsTrue(result.Contains("ALTER TABLE [Products] ADD [Cost]")); Assert.IsTrue(result.Contains("-- TODO: change manually (no ALTER COLUMN)")); }
public void GivenDroppedUniqueConstraint() { //arrange DatabaseSchema schema1 = CreateSchema(); DatabaseConstraint constraint = GetUniqueConstraint(); schema1.Tables[0].AddConstraint(constraint); DatabaseSchema schema2 = CreateSchema(); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.IsTrue(script.Contains("DROP CONSTRAINT [UK_NAME]"), script); }
public void GivenUniqueConstraintWithChangedColumn() { //arrange DatabaseSchema schema1 = CreateSchema(); DatabaseConstraint constraint = GetUniqueConstraint(); schema1.Tables[0].AddConstraint(constraint); DatabaseSchema schema2 = CreateSchema(); DatabaseConstraint constraint2 = GetUniqueConstraint(); constraint2.Columns[0] = "Desc"; schema2.Tables[0].AddConstraint(constraint2); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.IsTrue(script.Contains("DROP CONSTRAINT [UK_NAME]"), script); Assert.IsTrue(script.Contains("ADD CONSTRAINT [UK_NAME] UNIQUE"), script); }
public void GivenSameUniqueConstraint() { //arrange DatabaseSchema schema1 = CreateSchema(); DatabaseConstraint constraint = GetUniqueConstraint(); schema1.Tables[0].AddConstraint(constraint); DatabaseSchema schema2 = CreateSchema(); DatabaseConstraint constraint2 = GetUniqueConstraint(); schema2.Tables[0].AddConstraint(constraint2); //act var comparison = new CompareSchemas(schema1, schema2); var script = comparison.Execute(); //assert Assert.AreEqual(string.Empty, script); }