Ejemplo n.º 1
0
        public void TearDown()
        {
            if (!_processor.WasCommitted)
            {
                _processor.CommitTransaction();
            }
            _connection.Close();

            FbConnection.ClearPool(_connection);
            FbConnection.DropDatabase(IntegrationTestOptions.Firebird.ConnectionString);
        }
Ejemplo n.º 2
0
        public void TearDown()
        {
            if (_processor == null)
            {
                return;
            }

            if (!_processor.WasCommitted)
            {
                _processor.CommitTransaction();
            }
            _connection.Close();

            FbDatabase.DropDatabase(_temporaryDatabase.ConnectionString);
        }
        public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            var tempResources = WriteOutFirebirdEmbeddedLibrariesToCurrentWorkingDirectory();
            var tempFile      = Path.GetTempFileName();

            using (var deleter = new AutoDeleter(tempFile))
            {
                File.Delete(tempFile);
                deleter.Add(tempResources);
                var connectionString = GetConnectionStringToTempDatabaseAt(tempFile);

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations"
                };
                try
                {
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        options.TruncateLongNames = false;
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                        processor.CommitTransaction();
                        FbConnection.ClearPool(connection);
                    }
                    //---------------Assert Precondition----------------
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after first migration");
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichAltersTableWithFK());
                        processor.CommitTransaction();
                    }
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after second migration");
                }
                catch (Exception ex)
                {
                    try { File.Copy(tempFile, "C:\\tmp\\fm_tests.fdb", true); }
                    catch { }
                    throw ex;
                }
            }
        }
        public void ObsoleteAlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
            {
                var connectionString = tempDb.ConnectionString;

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(TestContext.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations"
                };

                using (var connection = new FbConnection(connectionString))
                {
                    var announcer = new TextWriterAnnouncer(TestContext.Out)
                    {
                        ShowSql = true
                    };
                    var options = FirebirdOptions.AutoCommitBehaviour();
                    options.TruncateLongNames = false;
                    var processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                    var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                    runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                    processor.CommitTransaction();
                    FbConnection.ClearPool(connection);
                }

                //---------------Assert Precondition----------------
                Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                              "Foreign key does not exist after first migration");
                using (var connection = new FbConnection(connectionString))
                {
                    var announcer = new TextWriterAnnouncer(TestContext.Out)
                    {
                        ShowSql = true
                    };
                    var options   = FirebirdOptions.AutoCommitBehaviour();
                    var processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                    var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                    runner.Up(new MigrationWhichAltersTableWithFK());
                    processor.CommitTransaction();
                }

                Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                              "Foreign key does not exist after second migration");
            }
        }
        public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            // this test was originally created to investigate an issue with foreign key names but in the process,
            // I found that FirebirdProcessor.CreateSequenceForIdentity doesn't respect FBOptions.UndoEnabled. Since
            // Undo isn't implemented for Firebird, a migration runner always has to turn it off, but even with it off,
            // the migrations below will fail unless CreateSequenceForIdentity is appropriately altered
            var tempResources = WriteOutFirebirdEmbeddedLibrariesToCurrentWorkingDirectory();
            var tempFile = Path.GetTempFileName();
            using (var deleter = new AutoDeleter(tempFile))
            {
                File.Delete(tempFile);
                deleter.Add(tempResources);
                var connectionString = GetConnectionStringToTempDatabaseAt(tempFile);

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                                            {
                                                Namespace = "FluentMigrator.Tests.Integration.Migrations"
                                            };


                try
                {
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        options.TruncateLongNames = false;
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                            new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                        processor.CommitTransaction();
                        FbConnection.ClearPool(connection);
                    }
                    //---------------Assert Precondition----------------
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                        "Foreign key does not exist after first migration");
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                            new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichAltersTableWithFK());
                        processor.CommitTransaction();

                    }
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                        "Foreign key does not exist after second migration");

                }
                catch (Exception ex)
                {
                    try { File.Copy(tempFile, "C:\\tmp\\fm_tests.fdb", true); }
                    catch { }
                    throw ex;

                }
            }
        }
Ejemplo n.º 6
0
        public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            // this test was originally created to investigate an issue with foreign key names but in the process,
            // I found that FirebirdProcessor.CreateSequenceForIdentity doesn't respect FBOptions.UndoEnabled. Since
            // Undo isn't implemented for Firebird, a migration runner always has to turn it off, but even with it off,
            // the migrations below will fail unless CreateSequenceForIdentity is appropriately altered
            var tempResources = WriteOutFirebirdEmbeddedLibrariesToCurrentWorkingDirectory();
            var tempFile      = Path.GetTempFileName();

            using (var deleter = new AutoDeleter(tempFile))
            {
                File.Delete(tempFile);
                deleter.Add(tempResources);
                var connectionString = GetConnectionStringToTempDatabaseAt(tempFile);

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations"
                };


                try
                {
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        options.TruncateLongNames = false;
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                        processor.CommitTransaction();
                        FbConnection.ClearPool(connection);
                    }
                    //---------------Assert Precondition----------------
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after first migration");
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichAltersTableWithFK());
                        processor.CommitTransaction();
                    }
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after second migration");
                }
                catch (Exception ex)
                {
                    try { File.Copy(tempFile, "C:\\tmp\\fm_tests.fdb", true); }
                    catch { }
                    throw ex;
                }
            }
        }
        public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            var tempResources = WriteOutFirebirdEmbeddedLibrariesToCurrentWorkingDirectory();
            var tempFile = Path.GetTempFileName();
            using (var deleter = new AutoDeleter(tempFile))
            {
                File.Delete(tempFile);
                deleter.Add(tempResources);
                var connectionString = GetConnectionStringToTempDatabaseAt(tempFile);

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                                            {
                                                Namespace = "FluentMigrator.Tests.Integration.Migrations"
                                            };
                try
                {
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        options.TruncateLongNames = false;
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                            new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                        processor.CommitTransaction();
                        FbConnection.ClearPool(connection);
                    }
                    //---------------Assert Precondition----------------
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                        "Foreign key does not exist after first migration");
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                            new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichAltersTableWithFK());
                        processor.CommitTransaction();

                    }
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                        "Foreign key does not exist after second migration");

                }
                catch (Exception ex)
                {
                    try { File.Copy(tempFile, "C:\\tmp\\fm_tests.fdb", true); }
                    catch { }
                    throw ex;

                }
            }
        }