public void TryUnloadVirtualEndPointAndItemData_Failure_InHigherTransaction()
        {
            var customer             = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var parentOrdersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            EnsureEndPointLoadedAndComplete(parentOrdersEndPoint.ID);

            customer.Orders[0].RegisterForCommit();

            Assert.That(parentOrdersEndPoint.Collection[0].State, Is.EqualTo(StateType.Changed));

            var subTransaction    = TestableClientTransaction.CreateSubTransaction();
            var subOrdersEndPoint = (ICollectionEndPoint)ClientTransactionTestHelper.GetDataManager(subTransaction).GetRelationEndPointWithLazyLoad(
                parentOrdersEndPoint.ID);

            EnsureEndPointLoadedAndComplete(ClientTransactionTestHelper.GetDataManager(subTransaction), subOrdersEndPoint.ID);

            Assert.That(subOrdersEndPoint.Collection[0].TransactionContext[subTransaction].State, Is.EqualTo(StateType.Unchanged));

            var result = UnloadService.TryUnloadVirtualEndPointAndItemData(subTransaction, parentOrdersEndPoint.ID);

            Assert.That(result, Is.False);
            Assert.That(subOrdersEndPoint.IsDataComplete, Is.True);
            Assert.That(parentOrdersEndPoint.IsDataComplete, Is.True);
        }
Exemplo n.º 2
0
        public void PerformCollectionRemoveWithOtherClientTransaction()
        {
            var order1     = DomainObjectIDs.Order1.GetObject <Order> ();
            var orderItem1 = DomainObjectMother.GetObjectInOtherTransaction <OrderItem> (DomainObjectIDs.OrderItem1);

            var endPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order1.OrderItems);

            endPoint.Collection.Remove(orderItem1);
        }
        public void UnloadVirtualEndPoint_Collection_AlreadyUnloaded()
        {
            var customer = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var endPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPoint.ID);
            ClientTransactionTestHelperWithMocks.EnsureTransactionThrowsOnEvents(TestableClientTransaction);
            Assert.That(endPoint.IsDataComplete, Is.False);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPoint.ID);
        }
        public void UnloadVirtualEndPointAndItemData_Collection_EmptyCollection_UnloadsEndPoint()
        {
            var customer       = DomainObjectIDs.Customer2.GetObject <Customer> ();
            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            EnsureEndPointLoadedAndComplete(ordersEndPoint.ID);

            Assert.That(ordersEndPoint.Collection, Is.Empty);

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID);

            Assert.That(ordersEndPoint.IsDataComplete, Is.False);
            Assert.That(customer.State, Is.EqualTo(StateType.Unchanged));
        }
        public void TryUnloadVirtualEndPointAndItemData_Success_IfDataNotComplete()
        {
            var customer       = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, ordersEndPoint.ID);
            Assert.That(ordersEndPoint.IsDataComplete, Is.False);

            ClientTransactionTestHelperWithMocks.EnsureTransactionThrowsOnEvents(TestableClientTransaction);

            var result = UnloadService.TryUnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID);

            Assert.That(result, Is.True);
            Assert.That(ordersEndPoint.IsDataComplete, Is.False);
        }
Exemplo n.º 6
0
        public void DomainObjectCollection_StandAlone_Contents()
        {
            var collection = new DomainObjectCollection(typeof(Order));

            collection.Add(DomainObjectIDs.Order1.GetObject <Order> ());

            DomainObjectCollection deserializedCollection = SerializeAndDeserialize(collection);

            Assert.That(deserializedCollection.Count, Is.EqualTo(1));
            Assert.That(deserializedCollection.Contains(DomainObjectIDs.Order1), Is.True);
            Assert.That(deserializedCollection[0].ID, Is.EqualTo(DomainObjectIDs.Order1));
            Assert.That(deserializedCollection.RequiredItemType, Is.EqualTo(typeof(Order)));
            Assert.That(deserializedCollection.IsReadOnly, Is.False);
            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(deserializedCollection), Is.Null);
        }
        public void UnloadVirtualEndPointAndItemData_Collection_UnloadsEndPointAndItems()
        {
            var order = DomainObjectIDs.Order1.GetObject <Order> ();
            var orderItemsEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order.OrderItems);

            EnsureEndPointLoadedAndComplete(orderItemsEndPoint.ID);

            var orderItem1 = orderItemsEndPoint.Collection[0];
            var orderItem2 = orderItemsEndPoint.Collection[1];

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, orderItemsEndPoint.ID);

            Assert.That(orderItemsEndPoint.IsDataComplete, Is.False);
            Assert.That(orderItem1.State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(orderItem2.State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(order.State, Is.EqualTo(StateType.Unchanged));
        }
Exemplo n.º 8
0
        private OrderCollection CreateAssociatedCollectionWithEndPointStub()
        {
            var collectionEndPointStub = MockRepository.GenerateStub <ICollectionEndPoint> ();
            var endPointDataStub       = new ReadOnlyCollectionDataDecorator(new DomainObjectCollectionData());

            collectionEndPointStub.Stub(stub => stub.GetData()).Return(endPointDataStub);

            var virtualEndPointProviderStub = MockRepository.GenerateStub <IVirtualEndPointProvider>();
            var endPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders");

            virtualEndPointProviderStub.Stub(stub => stub.GetOrCreateVirtualEndPoint(endPointID)).Return(collectionEndPointStub);

            var delegatingStrategy   = new EndPointDelegatingCollectionData(endPointID, virtualEndPointProviderStub);
            var associatedCollection = new OrderCollection(new ModificationCheckingCollectionDataDecorator(typeof(Order), delegatingStrategy));

            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(associatedCollection), Is.SameAs(collectionEndPointStub));
            return(associatedCollection);
        }
        public void TryUnloadVirtualEndPointAndItemData_Failure_EndPointChanged_EndPointAndItemsStillLoaded()
        {
            var customer = DomainObjectIDs.Customer1.GetObject <Customer> ();

            var orderA = customer.Orders[0];
            var orderB = customer.Orders[1];

            customer.Orders.Remove(orderB);

            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            Assert.That(ordersEndPoint.HasChanged, Is.True);
            Assert.That(orderA.State, Is.EqualTo(StateType.Unchanged));

            var result = UnloadService.TryUnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID);

            Assert.That(result, Is.False);
            Assert.That(orderA.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(ordersEndPoint.IsDataComplete, Is.True);
        }
        public void UnloadVirtualEndPointAndItemData_ThrowsAndDoesNothing_IfItemCannotBeUnloaded()
        {
            var customer       = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            var orderA = (Order)ordersEndPoint.Collection[0];
            var orderB = (Order)ordersEndPoint.Collection[1];

            // this will cause the orderB to be rejected for unload; orderA won't be unloaded either although it comes before orderB
            ++orderB.OrderNumber;

            Assert.That(orderA.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(orderB.State, Is.EqualTo(StateType.Changed));

            Assert.That(() => UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID), Throws.InvalidOperationException);

            Assert.That(orderA.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(orderB.State, Is.EqualTo(StateType.Changed));
            Assert.That(ordersEndPoint.IsDataComplete, Is.True);
        }
        public void UnloadVirtualEndPoint_Collection_ChangedCollectionReference_Throws()
        {
            var order = DomainObjectIDs.Order1.GetObject <Order> ();

            order.OrderItems = new ObjectList <OrderItem> (order.OrderItems); // new collection reference, same contents
            var endPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order.OrderItems);

            Assert.That(endPoint.HasChanged, Is.True);

            Assert.That(
                () => UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPoint.ID),
                Throws.InvalidOperationException.With.Message.EqualTo(
                    "The end point with ID "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems' has been "
                    + "changed. Changed end points cannot be unloaded."));

            Assert.That(UnloadService.TryUnloadVirtualEndPoint(TestableClientTransaction, endPoint.ID), Is.False);

            CheckVirtualEndPointExistsAndComplete(order, "OrderItems", true, true);
        }
        public void TryUnloadVirtualEndPointAndItemData_Failure_ItemCannotBeUnloaded_EndPointAndItemStillLoaded()
        {
            var customer       = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            var orderA = (Order)ordersEndPoint.Collection[0];
            var orderB = (Order)ordersEndPoint.Collection[1];

            // this will cause the orderB to be rejected for unload; orderA won't be unloaded either although it comes before orderB
            ++orderB.OrderNumber;

            Assert.That(orderA.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(orderB.State, Is.EqualTo(StateType.Changed));

            var result = UnloadService.TryUnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID);

            Assert.That(result, Is.False);
            Assert.That(orderA.State, Is.EqualTo(StateType.Unchanged));
            Assert.That(orderB.State, Is.EqualTo(StateType.Changed));
            Assert.That(ordersEndPoint.IsDataComplete, Is.True);
        }
Exemplo n.º 13
0
        public void DomainObjectCollection_Associated()
        {
            var customer1  = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var collection = customer1.Orders;
            var endPointID = collection.AssociatedEndPointID;
            var relatedIDs = collection.Select(obj => obj.ID).ToArray();

            var deserializedCollectionAndTransaction = Serializer.SerializeAndDeserialize(Tuple.Create(collection, TestableClientTransaction));
            var deserializedCollection  = deserializedCollectionAndTransaction.Item1;
            var deserializedTransaction = deserializedCollectionAndTransaction.Item2;

            var deserializedEndPoint = deserializedTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID);

            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(deserializedCollection), Is.SameAs(deserializedEndPoint));

            var deserializedData = DomainObjectCollectionDataTestHelper.GetDataStrategyAndCheckType <ModificationCheckingCollectionDataDecorator> (deserializedCollection);

            DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <EndPointDelegatingCollectionData> (deserializedData);

            Assert.That(collection.Select(obj => obj.ID).ToArray(), Is.EqualTo(relatedIDs));
        }
Exemplo n.º 14
0
        public void Clear_CancelAtSecondObject()
        {
            Assert.That(_oldCustomer.Orders, Is.EqualTo(new[] { _order1, _order2 }));

            var eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { _oldCustomer, _order1, _order2 },
                new[] { _oldCustomer.Orders });

            eventReceiver.CancelEventNumber = 6;

            try
            {
                _oldCustomer.Orders.Clear();
                Assert.Fail("Expected cancellation");
            }
            catch (EventReceiverCancelException)
            {
                // ok
            }

            var expectedStates = new ChangeState[]
            {
                new RelationChangeState(_order2, typeof(Order).FullName + ".Customer", _oldCustomer, null, "1. Setting _order2.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order2, "2. Removing _order2 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order2, null, "3. Removing _order2 from _oldCustomer"),

                new RelationChangeState(_order1, typeof(Order).FullName + ".Customer", _oldCustomer, null, "4. Setting _order1.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "5. Removing _order1 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order1, null, "6. Removing _order1 from _oldCustomer"),
            };

            eventReceiver.Check(expectedStates);

            Assert.That(_oldCustomer.Orders, Is.EqualTo(new[] { _order1, _order2 }));
            Assert.That(_order2.Customer, Is.SameAs(_oldCustomer));
            Assert.That(_order1.Customer, Is.SameAs(_oldCustomer));
            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(_oldCustomer.Orders).HasBeenTouched, Is.False);
        }
        public void UnloadVirtualEndPointAndItemData_AppliedToParentTransaction_UnloadsFromWholeHierarchy()
        {
            var order = DomainObjectIDs.Order1.GetObject <Order> ();
            var parentOrderItemsEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order.OrderItems);

            EnsureEndPointLoadedAndComplete(parentOrderItemsEndPoint.ID);

            var orderItem1 = parentOrderItemsEndPoint.Collection[0];

            var subTransaction        = TestableClientTransaction.CreateSubTransaction();
            var subOrderItemsEndPoint = ClientTransactionTestHelper.GetDataManager(subTransaction).GetRelationEndPointWithLazyLoad(
                parentOrderItemsEndPoint.ID);

            EnsureEndPointLoadedAndComplete(ClientTransactionTestHelper.GetDataManager(subTransaction), subOrderItemsEndPoint.ID);

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, parentOrderItemsEndPoint.ID);

            Assert.That(subOrderItemsEndPoint.IsDataComplete, Is.False);
            Assert.That(parentOrderItemsEndPoint.IsDataComplete, Is.False);

            Assert.That(orderItem1.TransactionContext[subTransaction].State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(orderItem1.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.NotLoadedYet));
        }
Exemplo n.º 16
0
        public void Clear_Events()
        {
            Assert.That(_oldCustomer.Orders, Is.EqualTo(new[] { _order1, _order2 }));

            var eventReceiver = new SequenceEventReceiver(
                new DomainObject[] { _oldCustomer, _order1, _order2 },
                new[] { _oldCustomer.Orders });

            _oldCustomer.Orders.Clear();

            var expectedStates = new ChangeState[]
            {
                new RelationChangeState(_order2, typeof(Order).FullName + ".Customer", _oldCustomer, null, "1. Setting _order2.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order2, "2. Removing _order2 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order2, null, "3. Removing _order2 from _oldCustomer"),

                new RelationChangeState(_order1, typeof(Order).FullName + ".Customer", _oldCustomer, null, "4. Setting _order1.Customer to null"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "5. Removing _order1 from _oldCustomer.Orders"),
                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", _order1, null, "6. Removing _order1 from _oldCustomer"),

                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", null, null, "7. Removed _order1 from _oldCustomer"),
                new CollectionChangeState(_oldCustomer.Orders, _order1, "8. Removed _order1 from _oldCustomer.Orders"),
                new RelationChangeState(_order1, typeof(Order).FullName + ".Customer", null, null, "9. Setting _order1.Customer to null"),

                new RelationChangeState(_oldCustomer, typeof(Customer).FullName + ".Orders", null, null, "10. Removed _order2 from _oldCustomer"),
                new CollectionChangeState(_oldCustomer.Orders, _order2, "11. Removed _order2 from _oldCustomer.Orders"),
                new RelationChangeState(_order2, typeof(Order).FullName + ".Customer", null, null, "12. Set _order2.Customer to null"),
            };

            eventReceiver.Check(expectedStates);

            Assert.That(_oldCustomer.Orders, Is.Empty);
            Assert.That(_order2.Customer, Is.Null);
            Assert.That(_order1.Customer, Is.Null);
            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(_oldCustomer.Orders).HasBeenTouched, Is.True);
        }