Ejemplo n.º 1
0
        public void ValidateVersionOrderingShouldReturnNothingIfNoUnappliedMigrations()
        {
            const long version1 = 2011010101;
            const long version2 = 2011010102;

            var mockMigration1 = new Mock <IMigration>();
            var mockMigration2 = new Mock <IMigration>();

            LoadVersionData(version1, version2);

            _migrationList.Clear();
            _migrationList.Add(version1, new MigrationInfo(version1, TransactionBehavior.Default, mockMigration1.Object));
            _migrationList.Add(version2, new MigrationInfo(version2, TransactionBehavior.Default, mockMigration2.Object));

            Assert.DoesNotThrow(() => _runner.ValidateVersionOrder());

            _announcer.Verify(a => a.Say("Version ordering valid."));

            _fakeVersionLoader.DidRemoveVersionTableGetCalled.ShouldBeFalse();
        }
Ejemplo n.º 2
0
        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>();
        }