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 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 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); }
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 Given2DatabasesThenDifferencesFound() { //arrange CreateDatabases(); //act var dsr1 = new DatabaseReader("Data Source=" + Db1Sqlite + ";Version=3;", SqlType.SQLite, commandTimeout: 5); var schema1 = dsr1.ReadAll(); var dsr2 = new DatabaseReader("Data Source=" + Db2Sqlite + ";Version=3;", SqlType.SQLite, commandTimeout: 5); 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)")); }