コード例 #1
0
ファイル: DbMigrationTest.cs プロジェクト: hardCTE/Rafy
        private void Test(Action<Database> action, Action<Database> assertAction)
        {
            using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
            {
                context.HistoryRepository = new DbHistoryRepository();
                context.RunDataLossOperation = DataLossOperation.All;

                var destination = context.ClassMetaReader.Read();
                action(destination);

                try
                {
                    context.MigrateTo(destination);

                    var result = context.DatabaseMetaReader.Read();
                    assertAction(result);
                }
                finally
                {
                    context.RollbackAll(RollbackAction.DeleteHistory);
                }
            }
        }
コード例 #2
0
ファイル: DbMigrationTest.cs プロジェクト: hardCTE/Rafy
        public void DMT_ManualMigrate()
        {
            using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
            {
                context.HistoryRepository = new DbHistoryRepository();
                context.RunDataLossOperation = DataLossOperation.All;

                try
                {
                    context.ManualMigrations.Clear();
                    context.ManualMigrations.Add(new DMT_ManualMigrateEntity());
                    context.ManualMigrations.Add(new DMT_ManualMigrateTest());

                    //手工更新
                    context.MigrateManually();

                    //历史记录
                    var histories = context.GetHistories();
                    Assert.IsTrue(histories.Count == 2);
                    Assert.IsTrue(histories[0] is DMT_ManualMigrateTest);
                    Assert.IsTrue(histories[1] is DMT_ManualMigrateEntity);

                    //数据库结构
                    var database = context.DatabaseMetaReader.Read();
                    var table = database.FindTable("TestingTable");
                    Assert.IsTrue(table.Columns.Count == 2);
                    var pk = table.FindPrimaryColumn();
                    Assert.IsTrue(pk.Name.EqualsIgnoreCase("Id"));
                    Assert.IsTrue(pk.DataType == DbType.Int32);

                    //数据库数据
                    using (var db = new DbAccesser(UnitTestEntityRepositoryDataProvider.DbSettingName))
                    {
                        var rows = db.QueryDataTable("select * from TestingTable");
                        Assert.IsTrue(rows.Rows.Count == 2);
                    }
                    var repo = RF.Find<TestUser>();
                    Assert.IsTrue(repo.CountAll() == 10);
                }
                finally
                {
                    //回滚
                    context.RollbackAll(RollbackAction.DeleteHistory);

                    var database = context.DatabaseMetaReader.Read();
                    Assert.IsTrue(database.FindTable("TestingTable") == null);
                }
            }
        }
コード例 #3
0
ファイル: DbMigrationTest.cs プロジェクト: hardCTE/Rafy
        public void DMT_RollbackAll()
        {
            using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
            {
                context.HistoryRepository = new DbHistoryRepository();
                context.RunDataLossOperation = DataLossOperation.All;

                context.RollbackAll(RollbackAction.DeleteHistory);

                var histories = context.GetHistories();

                Assert.IsTrue(histories.Count == 0);

                Assert.IsTrue(context.HasNoHistory());
            }
        }
コード例 #4
0
ファイル: DbMigrationTest.cs プロジェクト: hardCTE/Rafy
        public void DMT_DataLoss_DropTable()
        {
            using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
            {
                context.HistoryRepository = new DbHistoryRepository();

                var destination = context.ClassMetaReader.Read();
                var taskTable = destination.FindTable("Task");
                destination.Tables.Remove(taskTable);

                try
                {
                    context.MigrateTo(destination);

                    var result = context.DatabaseMetaReader.Read();
                    var resultTable = result.FindTable("Task");
                    Assert.IsTrue(resultTable != null);
                }
                finally
                {
                    context.RollbackAll(RollbackAction.DeleteHistory);
                }
            }
        }