public void CanUseCustomVersionInfo()
        {
            ExecuteWithSupportedProcessors(processor =>
            {
                var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3"
                }, processor);

                IVersionTableMetaData tableMetaData = new TestVersionTableMetaData();

                //ensure table doesn't exist
                if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName))
                {
                    runner.Down(new VersionMigration(tableMetaData));
                }

                //ensure schema doesn't exist
                if (processor.SchemaExists(tableMetaData.SchemaName))
                {
                    runner.Down(new VersionSchemaMigration(tableMetaData));
                }


                runner.Up(new VersionSchemaMigration(tableMetaData));
                processor.SchemaExists(tableMetaData.SchemaName).ShouldBeTrue();

                runner.Up(new VersionMigration(tableMetaData));
                processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeTrue();

                runner.Down(new VersionMigration(tableMetaData));
                processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeFalse();

                runner.Down(new VersionSchemaMigration(tableMetaData));
                processor.SchemaExists(tableMetaData.SchemaName).ShouldBeFalse();
            }, true, typeof(SqliteProcessor), typeof(MySqlProcessor), typeof(FirebirdProcessor));
        }
Beispiel #2
0
        public void CanRenameTable()
        {
            ExecuteWithSupportedProcessors(
                processor =>
            {
                var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor);

                runner.Up(new TestCreateAndDropTableMigration());
                processor.TableExists(null, "TestTable2").ShouldBeTrue();

                runner.Up(new TestRenameTableMigration());
                processor.TableExists(null, "TestTable2").ShouldBeFalse();
                processor.TableExists(null, "TestTable'3").ShouldBeTrue();

                runner.Down(new TestRenameTableMigration());
                processor.TableExists(null, "TestTable'3").ShouldBeFalse();
                processor.TableExists(null, "TestTable2").ShouldBeTrue();

                runner.Down(new TestCreateAndDropTableMigration());
                processor.TableExists(null, "TestTable2").ShouldBeFalse();

                //processor.CommitTransaction();
            });
        }
        public void CanUseVersionInfo()
        {
            ExecuteWithSupportedProcessors(processor =>
            {
                var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), new RunnerContext(new TextWriterAnnouncer(TestContext.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass3"
                }, processor);

                IVersionTableMetaData tableMetaData = new DefaultVersionTableMetaData();

                //ensure table doesn't exist
                if (processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName))
                {
                    runner.Down(new VersionMigration(tableMetaData));
                }

                runner.Up(new VersionMigration(tableMetaData));
                processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeTrue();

                runner.Down(new VersionMigration(tableMetaData));
                processor.TableExists(tableMetaData.SchemaName, tableMetaData.TableName).ShouldBeFalse();
            });
        }
Beispiel #4
0
        public void CanApplyIndexConventionWithSchema()
        {
            ExecuteWithSupportedProcessors(
                processor =>
            {
                var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor);

                runner.Up(new TestIndexNamingConventionWithSchema());
                processor.IndexExists("TestSchema", "Users", "IX_Users_GroupId").ShouldBeTrue();
                processor.TableExists("TestSchema", "Users").ShouldBeTrue();

                runner.Down(new TestIndexNamingConventionWithSchema());
                processor.IndexExists("TestSchema", "Users", "IX_Users_GroupId").ShouldBeFalse();
                processor.TableExists("TestSchema", "Users").ShouldBeFalse();
            });
        }
Beispiel #5
0
        public void CanRunMigration()
        {
            ExecuteWithSupportedProcessors(processor =>
            {
                var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor);

                runner.Up(new TestCreateAndDropTableMigration());

                processor.TableExists(null, "TestTable").ShouldBeTrue();

                // This is a hack until MigrationVersionRunner and MigrationRunner are refactored and merged together
                //processor.CommitTransaction();

                runner.Down(new TestCreateAndDropTableMigration());
                processor.TableExists(null, "TestTable").ShouldBeFalse();
            });
        }
Beispiel #6
0
        public void CanSilentlyFail()
        {
            var processorOptions = new Mock <IMigrationProcessorOptions>();

            processorOptions.SetupGet(x => x.PreviewOnly).Returns(false);

            var processor = new Mock <IMigrationProcessor>();

            processor.Setup(x => x.Process(It.IsAny <CreateForeignKeyExpression>())).Throws(new Exception("Error"));
            processor.Setup(x => x.Process(It.IsAny <DeleteForeignKeyExpression>())).Throws(new Exception("Error"));
            processor.Setup(x => x.Options).Returns(processorOptions.Object);

            var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), _runnerContext, processor.Object)
            {
                SilentlyFail = true
            };

            runner.Up(new TestForeignKeySilentFailure());

            runner.CaughtExceptions.Count.ShouldBeGreaterThan(0);

            runner.Down(new TestForeignKeySilentFailure());
            runner.CaughtExceptions.Count.ShouldBeGreaterThan(0);
        }
Beispiel #7
0
        public void VerifyTestMigrationSchema()
        {
            //run TestMigration migration, read, then remove...
            var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
            {
                Namespace = typeof(TestMigration).Namespace
            };

            var runner = new MigrationRunner(typeof(TestMigration).Assembly, runnerContext, Processor);

            runner.Up(new TestMigration());

            //read schema here
            IList <TableDefinition> defs = SchemaDumper.ReadDbSchema();

            SchemaTestWriter testWriter = new SchemaTestWriter();
            var    output          = GetOutput(testWriter, defs);
            string expectedMessage = testWriter.GetMessage(4, 10, 4, 1);

            runner.Down(new TestMigration());

            //test
            output.ShouldBe(expectedMessage);
        }
Beispiel #8
0
 public void CanAnnounceDown()
 {
     _announcer.Setup(x => x.Heading(It.IsRegex(ContainsAll("Test", "reverting"))));
     _runner.Down(new TestMigration());
     _announcer.VerifyAll();
 }
 public void MigrateDownOne()
 {
     Runner.Down(migrations.Pop());
 }