Ejemplo n.º 1
0
        public void DAT_EntityList_Migration()
        {
            //聚合实体
            var repo = RF.ResolveInstance <InvoiceRepository>();

            using (RF.TransactionScope(BackUpDbSettingName))
                using (RF.TransactionScope(DbSettingName))
                {
                    var invoiceList = new InvoiceList
                    {
                        new Invoice()
                        {
                            InvoiceItemList =
                            {
                                new InvoiceItem(),
                                new InvoiceItem(),
                            }
                        },
                        new Invoice()
                        {
                            InvoiceItemList =
                            {
                                new InvoiceItem(),
                                new InvoiceItem(),
                            }
                        },
                        new Invoice(),
                        new Invoice()
                    };

                    RF.Save(invoiceList);

                    Assert.AreEqual(repo.GetAll().Count, 4, "新增 Invoice 数目为4");

                    var context = new AggregationArchiveContext
                    {
                        OrignalDataDbSettingName = DbSettingName,
                        BackUpDbSettingName      = BackUpDbSettingName,
                        BatchSize             = 2,
                        DateOfArchiving       = DateTime.Now.AddMinutes(2),
                        AggregationsToArchive = new List <Type> {
                            typeof(Invoice)
                        }
                    };
                    var migrationSvc = new AggregationArchiver();
                    migrationSvc.Archive(context);

                    Assert.AreEqual(repo.GetAll().Count, 0, "执行数据归档后 Invoice 数目为 0");

                    using (RdbDataProvider.RedirectDbSetting(DbSettingName, BackUpDbSettingName))
                    {
                        Assert.AreEqual(repo.GetAll().Count, 4, "数据归档数据库 Invoice 数目为 4");
                    }
                }
        }
Ejemplo n.º 2
0
        public void DAT_TreeEntity_Migration()
        {
            //树形实体带聚合子

            var repo = RF.ResolveInstance <FolderRepository>();

            using (RF.TransactionScope(BackUpDbSettingName))
                using (RF.TransactionScope(DbSettingName))
                {
                    RF.Save(new Folder
                    {
                        Name         = "001.",
                        FileList     = { new File(), new File() },
                        TreeChildren =
                        {
                            new Folder
                            {
                                TreeChildren ={ new Folder()                    }
                            }
                        }
                    });
                    Assert.AreEqual(repo.GetAll().Count, 1, "树形实体只查根实体 Folder 数目为1");

                    var context = new AggregationArchiveContext
                    {
                        OrignalDataDbSettingName = DbSettingName,
                        BackUpDbSettingName      = BackUpDbSettingName,
                        BatchSize             = 2,
                        DateOfArchiving       = DateTime.Now.AddMinutes(2),
                        AggregationsToArchive = new List <Type> {
                            typeof(Folder)
                        }
                    };
                    var migrationSvc = new AggregationArchiver();
                    migrationSvc.Archive(context);

                    Assert.AreEqual(repo.GetAll().Count, 0, "执行数据归档后 Folder 数目为 0");

                    using (RdbDataProvider.RedirectDbSetting(DbSettingName, BackUpDbSettingName))
                    {
                        Assert.AreEqual(repo.GetAll().Count, 1, "归档数据库 Folder 数目为 3");
                        Assert.AreEqual(repo.GetAll()[0].FileList.Count, 2, "归档数据库聚合子 File 数目为 2");
                    }
                }
        }