public void Update_Database_Runs_New_Everytime_Script() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", "")); string scriptFileMd5 = ChangeScriptExecutor.GetFileMD5Hash(Path.Combine(scriptsDirectory, "Everytime", "TestScript.sql")); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Drop); //act bool success = new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update); //assert int records = 0; DatabaseIntegrationHelpers.AssertUsdAppliedDatabaseScriptTable(settings, reader => { while (reader.Read()) { records++; reader["ScriptFile"].ShouldEqual("TestScript.sql"); reader["hash"].ShouldEqual(scriptFileMd5); } }); success.ShouldEqual(true); records.ShouldEqual(1); }
public void Rebuild_Missing_Database_Generates_Database() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", string.Empty)); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); var aliaConsole = new ConsoleAliaSQL(); //act //database should not exist DropDatabaseIfExists(settings, scriptsDirectory); //assert aliaConsole.UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Rebuild).ShouldBeTrue(); int records = 0; DatabaseIntegrationHelpers.AssertUsdAppliedDatabaseScriptTable(settings, reader => { while (reader.Read()) { records++; reader["ScriptFile"].ShouldEqual("TestScript.sql"); } }); records.ShouldEqual(1); DropDatabaseIfExists(settings, scriptsDirectory); }
public void Update_Database_ShouldRun_Old_RunAlways_Script() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", "")); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Drop); //act //run once new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update).ShouldBeTrue(); new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(1); var dateApplied = DateTime.MinValue; QueryUsdAppliedDatabaseScriptTable(settings, reader => { while (reader.Read()) { reader["ScriptFile"].ShouldEqual("TestScript.sql"); dateApplied = (DateTime)reader["DateApplied"]; } }); dateApplied.ShouldBeGreaterThan(DateTime.MinValue); //delete TestTable to ensure script doesn't run again new QueryExecutor().ExecuteNonQuery(settings, "drop table TestTable", true); //run again bool success = new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update); //assert new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(1); DateTime dateAppliedUpdated = DateTime.MinValue;; int records = 0; QueryUsdAppliedDatabaseScriptTable(settings, reader => { while (reader.Read()) { records++; reader["ScriptFile"].ShouldEqual("TestScript.sql"); dateAppliedUpdated = (DateTime)reader["DateApplied"]; } }); success.ShouldBeTrue(); records.ShouldEqual(1); dateAppliedUpdated.ShouldBeGreaterThan(dateApplied); }
public void Update_Database_Skips_Old_Everytime_Script() { //arrange string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", "")); var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null); new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Drop); //act //run once new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update).ShouldBeTrue(); new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(1); //delete TestTable to ensure script doesn't run again new QueryExecutor().ExecuteNonQuery(settings, "drop table TestTable", true); //run again bool success = new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update); //assert new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(0); }