public void ValidateVersionOrderShouldThrowExceptionIfUnappliedMigrationVersionIsLessThanLatestAppliedMigration() { // Using SqlServer instead of SqlLite as versions not deleted from VersionInfo table when using Sqlite. var excludedProcessors = new[] { typeof(SqliteProcessor), typeof(MySqlProcessor), typeof(PostgresProcessor) }; var assembly = typeof(User).Assembly; var runnerContext1 = new RunnerContext(new TextWriterAnnouncer(System.Console.Out)) { Namespace = typeof(Migrations.Interleaved.Pass2.User).Namespace }; var runnerContext2 = new RunnerContext(new TextWriterAnnouncer(System.Console.Out)) { Namespace = typeof(Migrations.Interleaved.Pass3.User).Namespace }; VersionOrderInvalidException caughtException = null; try { ExecuteWithSupportedProcessors(processor => { var migrationRunner = new MigrationRunner(assembly, runnerContext1, processor); migrationRunner.MigrateUp(); }, false, excludedProcessors); ExecuteWithSupportedProcessors(processor => { var migrationRunner = new MigrationRunner(assembly, runnerContext2, processor); migrationRunner.ValidateVersionOrder(); }, false, excludedProcessors); } catch (VersionOrderInvalidException ex) { caughtException = ex; } finally { ExecuteWithSupportedProcessors(processor => { var migrationRunner = new MigrationRunner(assembly, runnerContext2, processor); migrationRunner.RollbackToVersion(0); }, true, excludedProcessors); } caughtException.ShouldNotBeNull(); caughtException.InvalidMigrations.Count().ShouldBe(1); var keyValuePair = caughtException.InvalidMigrations.First(); keyValuePair.Key.ShouldBe(200909060935); ((MigrationWithMetaDataAdapter)keyValuePair.Value).Migration.ShouldBeOfType <UserEmail>(); }
public void InvalidMigrationsPopulated() { var migrations = new[] { new KeyValuePair <long, IMigrationInfo>(1, new MigrationInfo(1, TransactionBehavior.Default, new TestMigration1())), new KeyValuePair <long, IMigrationInfo>(2, new MigrationInfo(2, TransactionBehavior.Default, new TestMigration2())) }; var exception = new VersionOrderInvalidException(migrations); exception.InvalidMigrations.ShouldBe(migrations); }
public void InvalidMigrationsPopulated() { var migrations = new[] { new KeyValuePair <long, IMigration>(1, new TestMigration1()), new KeyValuePair <long, IMigration>(2, new TestMigration2()) }; var exception = new VersionOrderInvalidException(migrations); exception.InvalidMigrations.ShouldBe(migrations); }
public void ExceptionMessageListsInvalidMigrations() { var migrations = new[] { new KeyValuePair <long, IMigrationInfo>(1, new MigrationInfo(1, TransactionBehavior.Default, new TestMigration1())), new KeyValuePair <long, IMigrationInfo>(2, new MigrationInfo(2, TransactionBehavior.Default, new TestMigration2())) }; var exception = new VersionOrderInvalidException(migrations); var expectedMessage = "Unapplied migrations have version numbers that are less than the greatest version number of applied migrations:" + Environment.NewLine + "1 - TestMigration1" + Environment.NewLine + "2 - TestMigration2"; System.Console.WriteLine(exception.Message); exception.Message.ShouldBe(expectedMessage); }
public void ExceptionMessageListsInvalidMigrationsWrappedByMigrationWithMetaDataAdapter() { var migrations = new[] { new KeyValuePair <long, IMigration>(1, new MigrationWithMetaDataAdapter(new TestMigration1(), new MigrationMetadata())), new KeyValuePair <long, IMigration>(2, new MigrationWithMetaDataAdapter(new TestMigration2(), new MigrationMetadata())) }; var exception = new VersionOrderInvalidException(migrations); var expectedMessage = "Unapplied migrations have version numbers that are less than the greatest version number of applied migrations:" + Environment.NewLine + "1 - TestMigration1" + Environment.NewLine + "2 - TestMigration2"; System.Console.WriteLine(exception.Message); exception.Message.ShouldBe(expectedMessage); }