Example #1
0
        public void EPT_Query()
        {
            var repo = RF.ResolveInstance <InvoiceRepository>();

            using (RF.TransactionScope(repo))
            {
                var Invoice = new Invoice();
                repo.Save(Invoice);
                Assert.AreEqual(repo.CountAll(), 1);

                Invoice.PersistenceStatus = PersistenceStatus.Deleted;
                repo.Save(Invoice);

                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                var all = repo.GetAll();
                Assert.AreEqual(all.Count, 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), 1, "幽灵状态的实体,可以使用特定 API 查出。");
                    var all2 = repo.GetAll();
                    Assert.AreEqual(all2.Count, 1, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }
Example #2
0
        public void EPT_BatchImport()
        {
            int size = EntityTest.BATCH_IMPORT_DATA_SIZE;

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

            using (RF.TransactionScope(repo))
            {
                var list = new InvoiceList();
                for (int i = 0; i < size; i++)
                {
                    var item = new Invoice();
                    list.Add(item);
                }
                repo.CreateImporter().Save(list);

                list.Clear();
                repo.CreateImporter().Save(list);

                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), size, "幽灵状态的实体,可以使用特定 API 查出。");
                    var all2 = repo.GetAll();
                    Assert.AreEqual(all2.Count, size, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }
Example #3
0
        public void EPT_Clear_Query()
        {
            var repo = RF.ResolveInstance <InvoiceRepository>();

            using (RF.TransactionScope(repo))
            {
                var InvoiceList = new InvoiceList
                {
                    new Invoice(),
                    new Invoice(),
                    new Invoice()
                };
                repo.Save(InvoiceList);
                Assert.AreEqual(repo.CountAll(), 3);

                InvoiceList.Clear();
                repo.Save(InvoiceList);
                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                var all = repo.GetAll();
                Assert.AreEqual(all.Count, 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), 3, "幽灵状态的实体,可以使用特定 API 查出。");
                    var all2 = repo.GetAll();
                    Assert.AreEqual(all2.Count, 3, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[1]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(all2[2]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }
Example #4
0
        public void EPT_BatchImport_Aggt()
        {
            if (IsTestDbSQLite())
            {
                return;
            }

            int size = EntityTest.BATCH_IMPORT_DATA_SIZE;

            var repo     = RF.ResolveInstance <InvoiceRepository>();
            var itemRepo = RF.ResolveInstance <InvoiceItemRepository>();

            using (RF.TransactionScope(repo))
            {
                var invoices = new InvoiceList();
                for (int i = 0; i < size; i++)
                {
                    var Invoice = new Invoice
                    {
                        InvoiceItemList =
                        {
                            new InvoiceItem(),
                            new InvoiceItem(),
                        }
                    };
                    invoices.Add(Invoice);
                }

                var importer = repo.CreateImporter();
                importer.Save(invoices);

                Assert.AreEqual(size, repo.CountAll());
                Assert.AreEqual(size * 2, itemRepo.CountAll());

                invoices.Clear();
                importer.Save(invoices);

                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                Assert.AreEqual(itemRepo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), size, "幽灵状态的实体,可以使用特定 API 查出。");
                    var roots = repo.GetAll();
                    Assert.AreEqual(roots.Count, size, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(roots[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");

                    Assert.AreEqual(itemRepo.CountAll(), size * 2, "幽灵状态的实体,可以使用特定 API 查出。");
                    var items = itemRepo.GetAll();
                    Assert.AreEqual(items.Count, size * 2, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(items[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }
Example #5
0
        public void EPT_Aggt()
        {
            var repo     = RF.ResolveInstance <InvoiceRepository>();
            var itemRepo = RF.ResolveInstance <InvoiceItemRepository>();

            using (RF.TransactionScope(repo))
            {
                var item = new Invoice
                {
                    InvoiceItemList =
                    {
                        new InvoiceItem(),
                        new InvoiceItem(),
                    }
                };

                repo.Save(item);

                Assert.AreEqual(1, repo.CountAll());
                Assert.AreEqual(2, itemRepo.CountAll());

                item.PersistenceStatus = PersistenceStatus.Deleted;
                repo.Save(item);

                Assert.AreEqual(repo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                Assert.AreEqual(itemRepo.CountAll(), 0, "幽灵状态的实体,应该无法通过正常的 API 查出。");

                using (PhantomContext.DontFilterPhantoms())
                {
                    Assert.AreEqual(repo.CountAll(), 1, "幽灵状态的实体,可以使用特定 API 查出。");
                    var roots = repo.GetAll();
                    Assert.AreEqual(roots.Count, 1, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(roots[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");

                    Assert.AreEqual(itemRepo.CountAll(), 2, "幽灵状态的实体,可以使用特定 API 查出。");
                    var items = itemRepo.GetAll();
                    Assert.AreEqual(items.Count, 2, "幽灵状态的实体,应该无法通过正常的 API 查出。");
                    Assert.AreEqual(EntityPhantomExtension.GetIsPhantom(items[0]), true, "幽灵状态的实体,IsPhantom 值为 true。");
                }
            }
        }