public void Run_should_rollback_all_migrations_if_TargetVersion_is_0() { // arrange // migrate up first _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 0; // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar <long>( "select max(version) from schema_migrations"); Assert.AreEqual(0, version, "schema version doesn't match TargetVersion"); var testTableCount = sql.ExecuteScalar <int>("select count(*) from information_schema.tables where table_name='TestTable'"); Assert.AreEqual(0, testTableCount, "not all migration scripts were run as expected"); } }
public void Run_should_leave_schema_unchanged_if_migration_script_throws_exception_when_migrating_down() { // arrange _mockMigrationScripts.Add(_mockScriptWithBadTeardown.Object); // migrate up first _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 0; // act try { _migrateCommand.Run(_commandArgs); } catch (MigrationException) { } // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar <long>( "select max(version) from schema_migrations"); Assert.AreEqual(4, version, "schema version doesn't match the original schema version"); var testTableCount = sql.ExecuteScalar <int>("select count(*) from information_schema.tables where table_name='TestTable'"); Assert.AreEqual(1, testTableCount, "schema changed"); } }
public void Run_should_leave_schema_unchanged_if_migration_script_throws_exception_when_migrating_down() { // arrange _mockMigrationScripts.Add(_mockScriptWithBadTeardown.Object); // migrate up first _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 0; // act try { _migrateCommand.Run(_commandArgs); } catch (MigrationException) { } // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>(SelectMaxVersionSql); Assert.AreEqual(4, version, "schema version doesn't match the original schema version"); var testTableCount = sql.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name='TestTable'"); Assert.AreEqual(1, testTableCount, "schema changed"); } }
public void Run_should_migrate_up_to_TargetVersion_if_greater_than_current_schema_version() { // arrange // migrate to version 1 first _commandArgs.TargetVersion = 1; _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 2; // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar <long>( "select max(version) from schema_migrations"); Assert.AreEqual(2, version, "schema version doesn't match TargetVersion"); var testTableId = sql.ExecuteScalar <int>("select max(Id) from [TestTable]"); Assert.AreEqual(2, testTableId, "not all migration scripts were run as expected"); } }
public void Run_should_migrate_to_latest_script_version_if_no_TargetVersion_is_given() { // arrange // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar <long>(SelectMaxVersionSql); Assert.AreEqual(2, version, "schema version doesn't match latest script version"); var testTableId = sql.ExecuteScalar <int>("select max(Id) from [TestTable]"); Assert.AreEqual(2, testTableId, "not all migration scripts were run as expected"); } }
public void Initialize_should_create_migration_table() { // act _subject.Initialize(); // assert long version; using (var helper = new SqlDatabaseHelper(TestConnectionString)) { version = helper.ExecuteScalar <long>("SELECT COUNT(Version) FROM [schema_migrations]"); } Assert.AreEqual(1, version); }
public void Run_should_create_schema_migrations_table_if_it_doesnt_exist() { // arrange _mockMigrationDir.Setup(dir => dir.GetScripts()).Returns(Enumerable.Empty <IMigrationScriptFile>); // act _versionCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var r = sql.ExecuteScalar <int>( "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='schema_migrations'"); Assert.IsTrue(r == 1); } }
public void ExecuteScript_should_perform_case_insensitive_replace_DNM_PROVIDER_token_in_script_with_the_current_ADO_provider_name() { // arrange using (var helper = new SqlDatabaseHelper(TestConnectionString)) { helper.ExecuteNonQuery("CREATE TABLE [providers] ([name] [nvarchar](100))"); // act _subject.OpenConnection(); using (var tran = _subject.BeginTransaction()) { _subject.ExecuteScript(tran, "INSERT INTO [providers] ([name]) VALUES ('/*dNm:PrOvIdEr*/')"); tran.Commit(); } // assert var providerNameInserted = helper.ExecuteScalar <string>("SELECT [name] FROM [providers]"); Assert.AreEqual("System.Data.SqlServerCe.4.0", providerNameInserted); } }
public void ExecuteScript_should_perform_case_insensitive_replace_DNM_PROVIDER_token_in_script_with_the_current_ADO_provider_name() { // arrange using (var helper = new SqlDatabaseHelper(TestConnectionString)) { helper.ExecuteNonQuery("CREATE TABLE [providers] ([name] [nvarchar](100))"); // act _subject.OpenConnection(); using (var tran = _subject.BeginTransaction()) { _subject.ExecuteScript(tran, "INSERT INTO [providers] ([name]) VALUES ('/*dNm:PrOvIdEr*/')"); tran.Commit(); } // assert var providerNameInserted = helper.ExecuteScalar<string>("SELECT [name] FROM [providers]"); Assert.AreEqual("System.Data.SqlServerCe.4.0", providerNameInserted); } }
public void Run_should_rollback_all_migrations_if_TargetVersion_is_0() { // arrange // migrate up first _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 0; // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>(SelectMaxVersionSql); Assert.AreEqual(0, version, "schema version doesn't match TargetVersion"); var testTableCount = sql.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name='TestTable'"); Assert.AreEqual(0, testTableCount, "not all migration scripts were run as expected"); } }
public void Run_should_migrate_up_to_TargetVersion_if_greater_than_current_schema_version() { // arrange // migrate to version 1 first _commandArgs.TargetVersion = 1; _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 2; // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>(SelectMaxVersionSql); Assert.AreEqual(2, version, "schema version doesn't match TargetVersion"); var testTableId = sql.ExecuteScalar<int>("select max(Id) from [TestTable]"); Assert.AreEqual(2, testTableId, "not all migration scripts were run as expected"); } }
public void Run_should_migrate_to_latest_script_version_if_no_TargetVersion_is_given() { // arrange // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>( "select max(version) from schema_migrations"); Assert.AreEqual(2, version, "schema version doesn't match latest script version"); var testTableId = sql.ExecuteScalar<int>("select max(Id) from [TestTable]"); Assert.AreEqual(2, testTableId, "not all migration scripts were run as expected"); } }