コード例 #1
0
        public void Run_should_set_MigrateCommandArgs_TargetVersion_to_previous_schema_version_in_schema_migrations_table()
        {
            //  arrange
            InitializeDatabase();

            //  insert some version numbers
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)");
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (2)");
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (3)");
            }

            _mockMigrateCommand.Protected().Setup("Execute", ItExpr.IsAny <MigrateCommandArgs>())
            .Callback((MigrateCommandArgs args) =>
                      Assert.AreEqual(2, args.TargetVersion));

            //  act
            _rollbackCommand.Run(_commandArgs);

            //  assert
            _mockMigrateCommand.Verify();
        }
コード例 #2
0
        public void Run_should_set_MigrateCommand_Log_to_its_own_Log()
        {
            //  arrange
            InitializeDatabase();

            //  insert some version numbers
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)");
            }

            //  act
            _rollbackCommand.Run(_commandArgs);

            //  assert
            Assert.AreSame(_rollbackCommand.Log, _mockMigrateCommand.Object.Log);
        }
コード例 #3
0
        public void Run_should_log_current_database_schema_version_from_schema_migrations_table()
        {
            //  arrange
            InitializeDatabase();

            _mockMigrationDir.Setup(dir => dir.GetScripts()).Returns(Enumerable.Empty <IMigrationScriptFile>);

            //  update schema_migrations table with a specific version number
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1234)");

                //  act
                _versionCommand.Run(_commandArgs);

                //  assert
                Assert.IsTrue(_mockLog.Output.Contains("Database is at version:".PadRight(30) + "1234"));
            }
        }
コード例 #4
0
        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_call_MigrateCommand_Execute_if_there_is_a_previous_version_to_rollback_to()
        {
            //  arrange
            InitializeDatabase();

            //  insert some version numbers
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)");
            }

            bool runCalled = false;
            _mockMigrateCommand.Protected().Setup("Execute", ItExpr.IsAny<MigrateCommandArgs>()).Callback(() => runCalled = true);

            //  act
            _rollbackCommand.Run(_commandArgs);

            //  assert
            Assert.IsTrue(runCalled);
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        public void Run_should_call_MigrateCommand_Execute_if_there_is_a_previous_version_to_rollback_to()
        {
            //  arrange
            InitializeDatabase();

            //  insert some version numbers
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)");
            }

            bool runCalled = false;

            _mockMigrateCommand.Protected().Setup("Execute", ItExpr.IsAny <MigrateCommandArgs>()).Callback(() => runCalled = true);

            //  act
            _rollbackCommand.Run(_commandArgs);

            //  assert
            Assert.IsTrue(runCalled);
        }
        public void Run_should_set_MigrateCommand_Log_to_its_own_Log()
        {
            //  arrange
            InitializeDatabase();

            //  insert some version numbers
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)");
            }

            //  act
            _rollbackCommand.Run(_commandArgs);

            //  assert
            Assert.AreSame(_rollbackCommand.Log, _mockMigrateCommand.Object.Log);
        }
        public void Run_should_set_MigrateCommandArgs_TargetVersion_to_previous_schema_version_in_schema_migrations_table()
        {
            //  arrange
            InitializeDatabase();

            //  insert some version numbers
            using (var sql = new SqlDatabaseHelper(TestConnectionString))
            {
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (3)");
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)");
                sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (2)");
            }

            _mockMigrateCommand.Protected().Setup("Execute", ItExpr.IsAny<MigrateCommandArgs>())
                .Callback((MigrateCommandArgs args) =>
                Assert.AreEqual(2, args.TargetVersion));

            //  act
            _rollbackCommand.Run(_commandArgs);

            //  assert
            _mockMigrateCommand.Verify();
        }