public void CanMoveDownWithoutTransaction()
        {
            var provider = new Mock<ITransformationProvider>();
            Assembly asm = Assembly.Load("ECM7.Migrator.TestAssembly");

            using (var migrator = new Migrator(provider.Object, asm))
            {
                migrator.ExecuteMigration(4, 4);

                provider.Verify(db => db.ExecuteNonQuery("down4"));
                provider.Verify(db => db.MigrationUnApplied(4, "test-key111"));
            }
        }
예제 #2
0
        public void CanMoveUpWithoutTransaction()
        {
            var      provider = new Mock <ITransformationProvider>();
            Assembly asm      = Assembly.Load("ECM7.Migrator.TestAssembly");

            using (var migrator = new Migrator(provider.Object, asm))
            {
                migrator.ExecuteMigration(4, 3);

                provider.Verify(db => db.ExecuteNonQuery("up4"));
                provider.Verify(db => db.MigrationApplied(4, "test-key111"));
            }
        }
예제 #3
0
        public void CanMoveUpWithoutTransaction()
        {
            var provider = new Mock <ITransformationProvider>();
            var assembly = GetType().GetTypeInfo().Assembly;

            using (var migrator = new Migrator(provider.Object, assembly))
            {
                migrator.ExecuteMigration(4, 3);

                provider.Verify(db => db.ExecuteNonQuery("up4"));
                provider.Verify(db => db.MigrationApplied(4, "test-key111"));
            }
        }
        public void CanMoveUp()
        {
            var provider = new Mock<ITransformationProvider>();
            Assembly asm = Assembly.Load("ECM7.Migrator.TestAssembly");

            using (var migrator = new Migrator(provider.Object, asm))
            {
                migrator.ExecuteMigration(2, 1);

                provider.Verify(db => db.BeginTransaction());
                provider.Verify(db => db.ExecuteNonQuery("up"));
                provider.Verify(db => db.MigrationApplied(2, "test-key111"));
                provider.Verify(db => db.Commit());
            }
        }
예제 #5
0
        public void CanMoveDown()
        {
            var provider = new Mock <ITransformationProvider>();
            var assembly = GetType().GetTypeInfo().Assembly;

            using (var migrator = new Migrator(provider.Object, assembly))
            {
                migrator.ExecuteMigration(2, 2);

                provider.Verify(db => db.BeginTransaction());
                provider.Verify(db => db.ExecuteNonQuery("down"));
                provider.Verify(db => db.MigrationUnApplied(2, "test-key111"));
                provider.Verify(db => db.Commit());
            }
        }
예제 #6
0
        public void CanMoveDown()
        {
            var      provider = new Mock <ITransformationProvider>();
            Assembly asm      = Assembly.Load("ECM7.Migrator.TestAssembly");

            using (var migrator = new Migrator(provider.Object, asm))
            {
                migrator.ExecuteMigration(2, 2);

                provider.Verify(db => db.BeginTransaction());
                provider.Verify(db => db.ExecuteNonQuery("down"));
                provider.Verify(db => db.MigrationUnApplied(2, "test-key111"));
                provider.Verify(db => db.Commit());
            }
        }
예제 #7
0
        public void ShouldNoRollbackWhenExceptionWithoutTransaction()
        {
            var provider = new Mock <ITransformationProvider>();
            var assembly = GetType().GetTypeInfo().Assembly;

            provider
            .Setup(db => db.MigrationUnApplied(It.IsAny <long>(), It.IsAny <string>()))
            .Throws <Exception>();

            using (var migrator = new Migrator(provider.Object, assembly))
            {
                Assert.Throws <Exception>(() => migrator.ExecuteMigration(2, 2));

                provider.Verify(db => db.MigrationUnApplied(2, It.IsAny <string>()));
            }
        }
예제 #8
0
        public void ShouldNoRollbackWhenExceptionWithoutTransaction()
        {
            Assembly asm      = Assembly.Load("ECM7.Migrator.TestAssembly");
            var      provider = new Mock <ITransformationProvider>();

            provider
            .Setup(db => db.MigrationUnApplied(It.IsAny <long>(), It.IsAny <string>()))
            .Throws <Exception>();

            using (var migrator = new Migrator(provider.Object, asm))
            {
                Assert.Throws <Exception>(() => migrator.ExecuteMigration(2, 2));

                provider.Verify(db => db.MigrationUnApplied(2, It.IsAny <string>()));
            }
        }
예제 #9
0
        /*end of add DbSets*/

        public void Migrate(string connectionString)
        {
            using (var loggerFactory = new LoggerFactory())
            {
                var logger = loggerFactory.CreateLogger("Migration");

                using (var migrator = new Migrator("postgres", connectionString, Assembly.GetAssembly(typeof(AppDbContext)), logger))
                {
                    HashSet <long> applied = new HashSet <long>(migrator.GetAppliedMigrations());
                    foreach (var migrationInfo in migrator.AvailableMigrations.OrderBy(m => m.Version))
                    {
                        if (!applied.Contains(migrationInfo.Version))
                        {
                            migrator.ExecuteMigration(migrationInfo.Version, migrationInfo.Version - 1);
                        }
                    }
                }
            }
        }
        public void ShouldNoRollbackWhenExceptionWithoutTransaction()
        {
            Assembly asm = Assembly.Load("ECM7.Migrator.TestAssembly");
            var provider = new Mock<ITransformationProvider>();

            provider
                .Setup(db => db.MigrationUnApplied(It.IsAny<long>(), It.IsAny<string>()))
                .Throws<Exception>();

            using (var migrator = new Migrator(provider.Object, asm))
            {
                Assert.Throws<Exception>(() => migrator.ExecuteMigration(2, 2));

                provider.Verify(db => db.MigrationUnApplied(2, It.IsAny<string>()));
            }
        }