public void TestMigrateMultipleFiles3()
        {
            SqlDatabaseHelper.ClearDatabase();
            Sql2008Migrator migrator = new Sql2008Migrator(SqlDatabaseHelper.DefaultConnectionString);

            var files = new IMigrationFile[] {
                new MigrationFile_03_DropTable(),
                new MigrationFile_01_CreateTable(),
                new MigrationFile_02_AlterTable(),
                new MigrationFile_04_AddColumn(),
                new MigrationFile_07_RenameColumn(),
                new MigrationFile_05_AlterColumn(),
                new MigrationFile_06_DropColumn(),
                new MigrationFile_08_TableExists(),
                new MigrationFile_10_CreatePrimaryKey(),
                new MigrationFile_09_RenameTable(),
                new MigrationFile_13_DropConstraint(),
                new MigrationFile_11_CreateForeignKey(),
                new MigrationFile_12_CreateUnique()
            };
            string s = migrator.Migrate(files).EndId;

            Assert.AreEqual("13_01", s);

            migrator.Dispose();
        }
Beispiel #2
0
        public void Test_01_CreateTable()
        {
            SqlDatabaseHelper.ClearDatabase();
            Sql2008Migrator migrator = new Sql2008Migrator(SqlDatabaseHelper.DefaultConnectionString);

            string s = migrator.Migrate(new MigrationFile_01_CreateTable()).EndId;

            Assert.AreEqual("01_03_CreateTable3", s);
            s = migrator.Migrate(new MigrationFile_01_CreateTable()).EndId;
            Assert.AreEqual("01_03_CreateTable3", s);
            migrator.Dispose();
        }
        public void TestMigrateAssembly()
        {
            SqlDatabaseHelper.ClearDatabase();
            Sql2008Migrator migrator = new Sql2008Migrator(SqlDatabaseHelper.DefaultConnectionString);

            var    assembly = this.GetType().Assembly;
            string s        = migrator.Migrate(assembly, "DatabaseAutoMigrator.Tests.TestFiles").EndId;

            Assert.AreEqual("13_01", s);

            s = migrator.Migrate(assembly, "DatabaseAutoMigrator.Tests.TestFiles").EndId;
            Assert.AreEqual("13_01", s);

            migrator.Dispose();
        }
        public void TestMigrateResult()
        {
            SqlDatabaseHelper.ClearDatabase();
            Sql2008Migrator migrator = new Sql2008Migrator(SqlDatabaseHelper.DefaultConnectionString);

            var result = migrator.Migrate(new MigrationFile_MigrateResult());

            Assert.AreEqual("", result.StartId);
            Assert.AreEqual("99_Error2", result.EndId);
            Assert.IsTrue(result.Duration.Ticks > 0);
            Assert.AreEqual(3, result.Executed.Count);
            Assert.AreEqual(1, result.NotExecuted.Count);

            Assert.IsTrue(result.Executed[0].Duration.Ticks > 0);
            Assert.IsTrue(result.Executed[0].Success);
            Assert.IsNull(result.Executed[0].Error);
            Assert.AreEqual("DatabaseAutoMigrator.Tests.TestFiles.MigrationFile_MigrateResult", result.Executed[0].File);
            Assert.AreEqual("Migrate_99_Error1", result.Executed[0].MethodName);

            Assert.IsTrue(result.Executed[2].Duration.Ticks > 0);
            Assert.IsFalse(result.Executed[2].Success);
            Assert.IsNotNull(result.Executed[2].Error);
            Assert.AreEqual("DatabaseAutoMigrator.Tests.TestFiles.MigrationFile_MigrateResult", result.Executed[2].File);
            Assert.AreEqual("Migrate_99_Error3", result.Executed[2].MethodName);

            Assert.IsFalse(result.NotExecuted[0].Success);
            Assert.IsNull(result.NotExecuted[0].Error);
            Assert.AreEqual("DatabaseAutoMigrator.Tests.TestFiles.MigrationFile_MigrateResult", result.NotExecuted[0].File);
            Assert.AreEqual("Migrate_99_Error4", result.NotExecuted[0].MethodName);

            result = migrator.Migrate(new MigrationFile_MigrateResult());
            Assert.AreEqual("99_Error2", result.StartId);
            Assert.AreEqual("99_Error2", result.EndId);
            Assert.IsTrue(result.Duration.Ticks > 0);
            Assert.AreEqual(1, result.Executed.Count);
            Assert.AreEqual(1, result.NotExecuted.Count);

            migrator.Dispose();
        }