Пример #1
0
        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);
                }
            }
        }
Пример #2
0
 public DataTable QueryDataTable(string formatSql, params object[] parameters)
 {
     return(_dba.QueryDataTable(formatSql, parameters));
 }