public void RenameTable_WhenOriginalTableContainsMultipleRows_ShouldNotFailToMigrate()
        {
            //---------------Set up test pack-------------------
            using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
            {
                using (var serviceProvider = CreateServiceProvider(tempDb.ConnectionString, "FluentMigrator.Tests.Integration.Migrations"))
                {
                    var runner = serviceProvider.GetRequiredService <IMigrationRunner>();
                    runner.Up(new CreateTableMigration());
                    runner.Up(new AddDataMigration(id: 1));
                    runner.Up(new AddDataMigration(2));
                    runner.Up(new AddDataMigration(3));
                    //---------------Assert Precondition----------------
                    var processor = serviceProvider.GetRequiredService <IMigrationProcessor>();
                    Assert.That(CountRowsWith("select count(*) as TheCount from TheTable", processor), Is.EqualTo(3));

                    //---------------Execute Test ----------------------
                    Exception thrown = null;
                    try
                    {
                        runner.Up(new RenameTableMigration());
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                    }

                    //---------------Test Result -----------------------
                    Assert.IsNull(thrown);
                }
            }
        }
예제 #2
0
        public void RenamingTable_WhenTableHasTextBlobs_ShouldCreateNewTableWithTextBlobsNotBinaryBlobs()
        {
            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))
                {
                    FirebirdProcessor processor;
                    var runner = CreateFirebirdEmbeddedRunnerFor(connection, runnerContext, out processor);
                    runner.Up(new MigrationWhichCreatesTableWithTextBlob());
                    //---------------Assert Precondition----------------
                    var fieldName            = "TheColumn";
                    var tableName            = "TheTable";
                    var expectedFieldType    = 261;
                    var expectedFieldSubType = 1;
                    AssertThatFieldHasCorrectTypeAndSubType(fieldName, tableName, connection, expectedFieldType, expectedFieldSubType);
                    //---------------Execute Test ----------------------
                    runner.Up(new MigrationWhichRenamesTableWithTextBlob());
                    //---------------Test Result -----------------------
                    tableName = "TheNewTable";
                    AssertThatFieldHasCorrectTypeAndSubType(fieldName, tableName, connection, expectedFieldType, expectedFieldSubType);
                }
            }
        }
        public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
            {
                using (var serviceProvider = CreateServiceProvider(tempDb.ConnectionString, "FluentMigrator.Tests.Integration.Migrations"))
                {
                    var runner    = serviceProvider.GetRequiredService <IMigrationRunner>();
                    var processor = serviceProvider.GetRequiredService <FirebirdProcessor>();
                    runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                    processor.CommitTransaction();
                    FbConnection.ClearPool((FbConnection)processor.Connection);
                }

                //---------------Assert Precondition----------------
                Assert.IsTrue(ForeignKeyExists(tempDb.ConnectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                              "Foreign key does not exist after first migration");
                using (var serviceProvider = CreateServiceProvider(tempDb.ConnectionString, "FluentMigrator.Tests.Integration.Migrations"))
                {
                    var runner    = serviceProvider.GetRequiredService <IMigrationRunner>();
                    var processor = serviceProvider.GetRequiredService <FirebirdProcessor>();
                    runner.Up(new MigrationWhichAltersTableWithFK());
                    processor.CommitTransaction();
                }

                Assert.IsTrue(ForeignKeyExists(tempDb.ConnectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                              "Foreign key does not exist after second migration");
            }
        }
예제 #4
0
        public void MigrationWithcAllRowsDelete_ShouldDeleteAllRows()
        {
            //---------------Set up test pack-------------------
            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))
                {
                    FirebirdProcessor processor;
                    var runner = CreateFirebirdEmbeddedRunnerFor(connection, runnerContext, out processor);
                    runner.Up(new CreateTableMigration());
                    runner.Up(new AddDataMigration(1));
                    runner.Up(new AddDataMigration(2));
                    runner.Up(new AddDataMigration(3));
                    //---------------Assert Precondition----------------
                    connection.Open();
                    const string countSql = "select count(*) as TheCount from TheTable";
                    using (var cmd = new FbCommand(countSql, connection))
                    {
                        using (var reader = cmd.ExecuteReader())
                        {
                            Assert.IsTrue(reader.Read());
                            Assert.AreEqual(3, Convert.ToInt32(reader["TheCount"]));
                        }
                    }
                    //---------------Execute Test ----------------------
                    Exception thrown = null;
                    try
                    {
                        runner.Up(new DeleteAllRowsMigration());
                        processor.CommitTransaction();
                        using (var cmd = new FbCommand(countSql, connection))
                        {
                            connection.Open();
                            using (var reader = cmd.ExecuteReader())
                            {
                                Assert.IsTrue(reader.Read());
                                Assert.AreEqual(0, Convert.ToInt32(reader["TheCount"]));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                    }


                    //---------------Test Result -----------------------
                    Assert.IsNull(thrown);
                }
            }
        }
예제 #5
0
 public void TearDown()
 {
     ServiceProvider?.Dispose();
     if (_temporaryDatabase != null)
     {
         var connString = _temporaryDatabase.ConnectionString;
         _temporaryDatabase = null;
         FbDatabase.DropDatabase(connString);
     }
 }
예제 #6
0
 public void SetUp()
 {
     if (!IntegrationTestOptions.Firebird.IsEnabled)
     {
         Assert.Ignore();
     }
     _temporaryDatabase = new TemporaryDatabase(
         IntegrationTestOptions.Firebird,
         _prober);
     _connection = new FbConnection(_temporaryDatabase.ConnectionString);
     _processor  = MakeProcessor();
     _connection.Open();
     _processor.BeginTransaction();
 }
        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 SetUp()
        {
            if (!IntegrationTestOptions.Firebird.IsEnabled)
            {
                Assert.Ignore();
            }
            _temporaryDatabase = new TemporaryDatabase(
                IntegrationTestOptions.Firebird,
                _prober);
            Connection = new FbConnection(_temporaryDatabase.ConnectionString);
            var options = FirebirdOptions.AutoCommitBehaviour();

            Processor = new FirebirdProcessor(Connection, new FirebirdGenerator(options), new TextWriterAnnouncer(TestContext.Out), new ProcessorOptions(), new FirebirdDbFactory(), options);
            Connection.Open();
            Processor.BeginTransaction();
        }
예제 #9
0
        public void OneMigrationWithOneBlanketUpdate_ShouldUpdateAffectedRow()
        {
            //---------------Set up test pack-------------------
            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))
                {
                    FirebirdProcessor processor;
                    var runner = CreateFirebirdEmbeddedRunnerFor(connection, runnerContext, out processor);
                    runner.Up(new CreateTableMigration());
                    runner.Up(new AddDataMigration(1));
                    runner.Up(new AddDataMigration(2));
                    runner.Up(new AddDataMigration(3));
                    //---------------Assert Precondition----------------
                    connection.Open();
                    const string countSql = "select count(*) as TheCount from TheTable where SomeValue = {0}";
                    Assert.AreEqual(1, CountRowsWith(countSql, 1, connection));
                    Assert.AreEqual(1, CountRowsWith(countSql, 2, connection));
                    Assert.AreEqual(1, CountRowsWith(countSql, 3, connection));
                    //---------------Execute Test ----------------------
                    Exception thrown = null;
                    try
                    {
                        runner.Up(new UpdateMigration(4));
                        processor.CommitTransaction();
                        Assert.AreEqual(3, CountRowsWith(countSql, 4, connection));
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                    }


                    //---------------Test Result -----------------------
                    Assert.IsNull(thrown);
                }
            }
        }
예제 #10
0
        public void SetUp()
        {
            if (!IntegrationTestOptions.Firebird.IsEnabled)
            {
                Assert.Ignore();
            }

            _temporaryDatabase = new TemporaryDatabase(
                IntegrationTestOptions.Firebird,
                _prober);

            var serivces = ServiceCollectionExtensions.CreateServices()
                           .ConfigureRunner(builder => builder.AddFirebird())
                           .AddScoped <IConnectionStringReader>(
                _ => new PassThroughConnectionStringReader(_temporaryDatabase.ConnectionString));

            ServiceProvider = serivces.BuildServiceProvider();
        }
예제 #11
0
        public void RenameTable_WhenOriginalTableExistsAndContainsDataWithNulls_ShouldNotThrowException()
        {
            //---------------Set up test pack-------------------
            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))
                {
                    FirebirdProcessor processor;
                    var runner = CreateFirebirdEmbeddedRunnerFor(connection, runnerContext, out processor);
                    runner.Up(new CreateTableMigration());
                    runner.Up(new AddDataMigration());
                    //---------------Assert Precondition----------------
                    connection.Open();
                    using (var cmd = new FbCommand("select * from TheTable", connection))
                    {
                        using (var reader = cmd.ExecuteReader())
                        {
                            Assert.IsTrue(reader.Read());
                            Assert.IsInstanceOf <DBNull>(reader["Name"]);
                        }
                    }
                    //---------------Execute Test ----------------------
                    Exception thrown = null;
                    try
                    {
                        runner.Up(new RenameTableMigration());
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                    }

                    //---------------Test Result -----------------------
                    Assert.IsNull(thrown);
                }
            }
        }
        public void RenameTable_WhenOriginalTableExistsAndContainsDataWithNulls_ShouldNotThrowException()
        {
            //---------------Set up test pack-------------------
            using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
            {
                using (var serviceProvider = CreateServiceProvider(tempDb.ConnectionString, "FluentMigrator.Tests.Integration.Migrations"))
                {
                    var runner = serviceProvider.GetRequiredService <IMigrationRunner>();
                    runner.Up(new CreateTableMigration());
                    runner.Up(new AddDataMigration(1));

                    //---------------Assert Precondition----------------
                    var processor = serviceProvider.GetRequiredService <IMigrationProcessor>();
                    var result    = processor.Read("select * from TheTable");

                    Assert.That(result.Tables.Count, Is.GreaterThan(0));
                    var table = result.Tables[0];

                    Assert.That(table.Rows.Count, Is.GreaterThan(0));
                    var row = table.Rows[0];

                    Assert.IsTrue(table.Columns.Contains("Name"));
                    Assert.That(row["Name"], Is.InstanceOf <DBNull>());

                    //---------------Execute Test ----------------------
                    Exception thrown = null;
                    try
                    {
                        runner.Up(new RenameTableMigration());
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                    }

                    //---------------Test Result -----------------------
                    Assert.IsNull(thrown);
                }
            }
        }
        public void OneMigrationWithOneBlanketUpdate_ShouldUpdateAffectedRow()
        {
            //---------------Set up test pack-------------------
            using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
            {
                using (var serviceProvider = CreateServiceProvider(tempDb.ConnectionString, "FluentMigrator.Tests.Integration.Migrations"))
                {
                    var runner = serviceProvider.GetRequiredService <IMigrationRunner>();
                    runner.Up(new CreateTableMigration());
                    runner.Up(new AddDataMigration(1));
                    runner.Up(new AddDataMigration(2));
                    runner.Up(new AddDataMigration(3));
                    //---------------Assert Precondition----------------
                    const string countSql  = "select count(*) as TheCount from TheTable where SomeValue = {0}";
                    var          processor = serviceProvider.GetRequiredService <FirebirdProcessor>();
                    Assert.That(CountRowsWith(countSql, processor, 1), Is.EqualTo(1));
                    Assert.That(CountRowsWith(countSql, processor, 2), Is.EqualTo(1));
                    Assert.That(CountRowsWith(countSql, processor, 3), Is.EqualTo(1));

                    //---------------Execute Test ----------------------
                    Exception thrown = null;
                    try
                    {
                        runner.Up(new UpdateMigration(4));
                        processor.CommitTransaction();
                        Assert.That(CountRowsWith(countSql, processor, 4), Is.EqualTo(3));
                    }
                    catch (Exception ex)
                    {
                        thrown = ex;
                    }


                    //---------------Test Result -----------------------
                    Assert.IsNull(thrown);
                }
            }
        }
 public void RenamingTable_WhenTableHasTextBlobs_ShouldCreateNewTableWithTextBlobsNotBinaryBlobs()
 {
     using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
     {
         using (var serviceProvider = CreateServiceProvider(tempDb.ConnectionString, "FluentMigrator.Tests.Integration.Migrations"))
         {
             var runner = serviceProvider.GetRequiredService <IMigrationRunner>();
             runner.Up(new MigrationWhichCreatesTableWithTextBlob());
             //---------------Assert Precondition----------------
             var fieldName            = "TheColumn";
             var tableName            = "TheTable";
             var expectedFieldType    = 261;
             var expectedFieldSubType = 1;
             var processor            = serviceProvider.GetRequiredService <FirebirdProcessor>();
             AssertThatFieldHasCorrectTypeAndSubType(fieldName, tableName, processor, expectedFieldType, expectedFieldSubType);
             //---------------Execute Test ----------------------
             runner.Up(new MigrationWhichRenamesTableWithTextBlob());
             //---------------Test Result -----------------------
             tableName = "TheNewTable";
             AssertThatFieldHasCorrectTypeAndSubType(fieldName, tableName, processor, expectedFieldType, expectedFieldSubType);
         }
     }
 }