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); keyValuePair.Value.Migration.ShouldBeOfType<UserEmail>(); }