Exemplo n.º 1
0
        public void TestEntityCaching_NewEntities()
        {
            CatalogEntityContainer container = new CatalogEntityContainer();

            // add two orders and a detail
            PurchaseOrder       order1 = new PurchaseOrder();
            PurchaseOrder       order2 = new PurchaseOrder();
            PurchaseOrderDetail detail = new PurchaseOrderDetail();

            container.GetEntitySet <PurchaseOrder>().Add(order1);
            container.GetEntitySet <PurchaseOrder>().Add(order2);
            container.GetEntitySet <PurchaseOrderDetail>().Add(detail);

            // examine the order ref of the detail - ensure that
            // no result is returned, since a FK query would match
            // BOTH orders
            Assert.IsNull(detail.PurchaseOrder);

            // now that we've cached a null, make sure that if more
            // new entities are added, the ref doesn't change
            container.GetEntitySet <PurchaseOrder>().Add(new PurchaseOrder());
            Assert.IsNull(detail.PurchaseOrder);

            // now assign order1, and remove order2 - make sure that our
            // ref to order1 remains
            detail.PurchaseOrder = order1;
            Assert.AreSame(order1, detail.PurchaseOrder);
            container.GetEntitySet <PurchaseOrder>().Remove(order2);
            Assert.AreSame(order1, detail.PurchaseOrder);

            container.GetEntitySet <PurchaseOrder>().Remove(order1);
            Assert.IsNull(detail.PurchaseOrder);
        }
Exemplo n.º 2
0
        public void TestEntityRefCaching()
        {
            CatalogEntityContainer container = new CatalogEntityContainer();

            PurchaseOrderDetail detail = new PurchaseOrderDetail {
                PurchaseOrderDetailID = 1,
                PurchaseOrderID       = 1
            };
            PurchaseOrder order = new PurchaseOrder {
                PurchaseOrderID = 1
            };
            PurchaseOrder order2 = new PurchaseOrder {
                PurchaseOrderID = 2
            };

            container.LoadEntities(new Entity[] { order, order2 });
            container.LoadEntities(new Entity[] { detail });

            // force the EntityRef to cache
            Assert.AreSame(order, detail.PurchaseOrder);

            // clear the entity set to verify that the cached
            // entity is cleared
            EntitySet purchaseOrderSet = container.GetEntitySet <PurchaseOrder>();

            purchaseOrderSet.Clear();
            Assert.AreEqual(0, purchaseOrderSet.Count);

            // after the set has been cleared, we expect null
            Assert.IsNull(detail.PurchaseOrder);

            // change the FK and verify that we requery again, getting no match
            // since all orders have been cleared from the set
            detail.PurchaseOrderID = 2;
            Assert.AreSame(null, detail.PurchaseOrder);

            // Reload the order entities and verify we get the
            // correct order
            container.LoadEntities(new Entity[] { order, order2 });
            Assert.AreSame(order2, detail.PurchaseOrder);

            // reset the FK and verify that we requery to get the
            // right entity
            detail.PurchaseOrderID = 1;
            Assert.AreSame(order, detail.PurchaseOrder);
        }
Exemplo n.º 3
0
        private void TestNotifications(CatalogEntityContainer ec)
        {
            // with only the order in the container
            // its collection returns empty
            Assert.IsNotNull(TestOrder.EntitySet);
            Assert.AreEqual(0, TestOrder.PurchaseOrderDetails.Count());
            Assert.AreEqual(0, NumNotifications);

            // after we load some entities, we expect a change notification
            ec.LoadEntities(TestDetails);
            Assert.AreEqual(TestDetails.Count, NumNotifications);
            Assert.IsTrue(TestDetails.SequenceEqual(TestOrder.PurchaseOrderDetails));

            // now add an entity that doesn't match the predicate and
            // verify we don't get notified
            NumNotifications = 0;
            ec.LoadEntities(new PurchaseOrderDetail[] { new PurchaseOrderDetail {
                                                            PurchaseOrderID = 9, PurchaseOrderDetailID = GetUniquePurchaseOrderID()
                                                        } });
            Assert.AreEqual(0, NumNotifications);

            // now load one matching and verify we get notified
            ec.LoadEntities(new PurchaseOrderDetail[] { new PurchaseOrderDetail {
                                                            PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID()
                                                        } });
            Assert.AreEqual(1, NumNotifications);

            // verify we get notified if the set is cleared
            NumNotifications = 0;
            EntitySet <PurchaseOrderDetail> entitySet = ec.GetEntitySet <PurchaseOrderDetail>();

            entitySet.Clear();
            Assert.AreEqual(1, NumNotifications);

            // verify that we can reuse the set and continue getting notifications
            NumNotifications = 0;
            ec.LoadEntities(new PurchaseOrderDetail[] { new PurchaseOrderDetail {
                                                            PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID()
                                                        } });
            Assert.AreEqual(1, NumNotifications);
        }
Exemplo n.º 4
0
        public void TestEntityRefCaching_Detach()
        {
            CatalogEntityContainer container = new CatalogEntityContainer();

            PurchaseOrderDetail detail = new PurchaseOrderDetail
            {
                PurchaseOrderDetailID = 1,
                PurchaseOrderID       = 1
            };
            PurchaseOrder order = new PurchaseOrder
            {
                PurchaseOrderID = 1
            };

            container.LoadEntities(new Entity[] { order, detail });

            Assert.AreSame(order, detail.PurchaseOrder);

            // now detach the detail and verify that the
            // cached entity is still returned
            container.GetEntitySet <PurchaseOrderDetail>().Detach(detail);
            Assert.AreSame(order, detail.PurchaseOrder);
        }
        private void TestNotifications(CatalogEntityContainer ec) {
            // with only the order in the container
            // its collection returns empty
            Assert.IsNotNull(TestOrder.EntitySet);
            Assert.AreEqual(0, TestOrder.PurchaseOrderDetails.Count());
            Assert.AreEqual(0, NumNotifications);

            // after we load some entities, we expect a change notification
            ec.LoadEntities(TestDetails);
            Assert.AreEqual(TestDetails.Count, NumNotifications);
            Assert.IsTrue(TestDetails.SequenceEqual(TestOrder.PurchaseOrderDetails));

            // now add an entity that doesn't match the predicate and
            // verify we don't get notified
            NumNotifications = 0;
            ec.LoadEntities(new PurchaseOrderDetail[] { new PurchaseOrderDetail { PurchaseOrderID = 9, PurchaseOrderDetailID = GetUniquePurchaseOrderID() } });
            Assert.AreEqual(0, NumNotifications);

            // now load one matching and verify we get notified
            ec.LoadEntities(new PurchaseOrderDetail[] { new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() } });
            Assert.AreEqual(1, NumNotifications);

            // verify we get notified if the set is cleared
            NumNotifications = 0;
            EntitySet<PurchaseOrderDetail> entitySet = ec.GetEntitySet<PurchaseOrderDetail>();
            entitySet.Clear();
            Assert.AreEqual(1, NumNotifications);

            // verify that we can reuse the set and continue getting notifications
            NumNotifications = 0;
            ec.LoadEntities(new PurchaseOrderDetail[] { new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() } });
            Assert.AreEqual(1, NumNotifications);
        }
        public void TestEntityRefCaching_Detach()
        {
            CatalogEntityContainer container = new CatalogEntityContainer();

            PurchaseOrderDetail detail = new PurchaseOrderDetail
            {
                PurchaseOrderDetailID = 1,
                PurchaseOrderID = 1
            };
            PurchaseOrder order = new PurchaseOrder
            {
                PurchaseOrderID = 1
            };

            container.LoadEntities(new Entity[] { order, detail });

            Assert.AreSame(order, detail.PurchaseOrder);

            // now detach the detail and verify that the
            // cached entity is still returned
            container.GetEntitySet<PurchaseOrderDetail>().Detach(detail);
            Assert.AreSame(order, detail.PurchaseOrder);
        }
        public void TestEntityCaching_NewEntities()
        {
            CatalogEntityContainer container = new CatalogEntityContainer();

            // add two orders and a detail
            PurchaseOrder order1 = new PurchaseOrder();
            PurchaseOrder order2 = new PurchaseOrder();
            PurchaseOrderDetail detail = new PurchaseOrderDetail();
            container.GetEntitySet<PurchaseOrder>().Add(order1);
            container.GetEntitySet<PurchaseOrder>().Add(order2);
            container.GetEntitySet<PurchaseOrderDetail>().Add(detail);

            // examine the order ref of the detail - ensure that
            // no result is returned, since a FK query would match
            // BOTH orders
            Assert.IsNull(detail.PurchaseOrder);

            // now that we've cached a null, make sure that if more
            // new entities are added, the ref doesn't change
            container.GetEntitySet<PurchaseOrder>().Add(new PurchaseOrder());
            Assert.IsNull(detail.PurchaseOrder);

            // now assign order1, and remove order2 - make sure that our
            // ref to order1 remains
            detail.PurchaseOrder = order1;
            Assert.AreSame(order1, detail.PurchaseOrder);
            container.GetEntitySet<PurchaseOrder>().Remove(order2);
            Assert.AreSame(order1, detail.PurchaseOrder);

            container.GetEntitySet<PurchaseOrder>().Remove(order1);
            Assert.IsNull(detail.PurchaseOrder);
        }
        public void TestEntityRefCaching() {
            CatalogEntityContainer container = new CatalogEntityContainer();

            PurchaseOrderDetail detail = new PurchaseOrderDetail {
                PurchaseOrderDetailID = 1,
                PurchaseOrderID = 1
            };
            PurchaseOrder order = new PurchaseOrder {
                PurchaseOrderID = 1
            };
            PurchaseOrder order2 = new PurchaseOrder {
                PurchaseOrderID = 2
            };

            container.LoadEntities(new Entity[] { order, order2});
            container.LoadEntities(new Entity[] { detail });

            // force the EntityRef to cache
            Assert.AreSame(order, detail.PurchaseOrder);

            // clear the entity set to verify that the cached
            // entity is cleared
            EntitySet purchaseOrderSet = container.GetEntitySet<PurchaseOrder>();
            purchaseOrderSet.Clear();
            Assert.AreEqual(0, purchaseOrderSet.Count);

            // after the set has been cleared, we expect null
            Assert.IsNull(detail.PurchaseOrder);

            // change the FK and verify that we requery again, getting no match
            // since all orders have been cleared from the set
            detail.PurchaseOrderID = 2;
            Assert.AreSame(null, detail.PurchaseOrder);

            // Reload the order entities and verify we get the
            // correct order
            container.LoadEntities(new Entity[] { order, order2 });
            Assert.AreSame(order2, detail.PurchaseOrder);

            // reset the FK and verify that we requery to get the
            // right entity
            detail.PurchaseOrderID = 1;
            Assert.AreSame(order, detail.PurchaseOrder);
        }