Beispiel #1
0
        public void ExpandToAllRelatedObjects()
        {
            var removedEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(_removedRelatedObject.ID, "Customer");
            var removedEndPoint   = (IObjectEndPoint)DataManager.GetRelationEndPointWithoutLoading(removedEndPointID);

            Assert.That(removedEndPoint, Is.Not.Null);

            EndPointProviderStub.Stub(stub => stub.GetRelationEndPointWithLazyLoad(removedEndPoint.ID)).Return(removedEndPoint);

            var bidirectionalModification = _command.ExpandToAllRelatedObjects();

            // DomainObject.Orders.Remove (_removedRelatedObject)
            var steps = bidirectionalModification.GetNestedCommands();

            Assert.That(steps.Count, Is.EqualTo(2));

            // _removedRelatedObject.Customer = null
            Assert.That(steps[0], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator)));
            var setCustomerCommand = ((ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[0]).DecoratedCommand);

            Assert.That(setCustomerCommand.ModifiedEndPoint, Is.SameAs(removedEndPoint));
            Assert.That(setCustomerCommand.OldRelatedObject, Is.SameAs(DomainObject));
            Assert.That(setCustomerCommand.NewRelatedObject, Is.Null);

            // DomainObject.Orders.Remove (_removedRelatedObject)
            Assert.That(steps[1], Is.SameAs(_command));
        }
        public override void SetUp()
        {
            base.SetUp();

            _collectionEndPointID    = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders");
            _virtualObjectEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderTicket");
        }
        public override void SetUp()
        {
            base.SetUp();

            _endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders");
            _changeDetectionStrategyMock = MockRepository.GenerateStrictMock <ICollectionEndPointChangeDetectionStrategy> ();

            _domainObject1 = DomainObjectMother.CreateFakeObject <Order> (DomainObjectIDs.Order1);
            _domainObject2 = DomainObjectMother.CreateFakeObject <Order> (DomainObjectIDs.Order3);
            _domainObject3 = DomainObjectMother.CreateFakeObject <Order> (DomainObjectIDs.Order4);
            _domainObject4 = DomainObjectMother.CreateFakeObject <Order> (DomainObjectIDs.Order5);

            _domainObjectEndPoint1 = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _domainObjectEndPoint1.Stub(stub => stub.GetDomainObjectReference()).Return(_domainObject1);
            _domainObjectEndPoint1.Stub(stub => stub.ObjectID).Return(_domainObject1.ID);

            _domainObjectEndPoint2 = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _domainObjectEndPoint2.Stub(stub => stub.GetDomainObjectReference()).Return(_domainObject2);
            _domainObjectEndPoint2.Stub(stub => stub.ObjectID).Return(_domainObject2.ID);

            _domainObjectEndPoint3 = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _domainObjectEndPoint3.Stub(stub => stub.GetDomainObjectReference()).Return(_domainObject3);
            _domainObjectEndPoint3.Stub(stub => stub.ObjectID).Return(_domainObject3.ID);

            _dataManager = new CollectionEndPointDataManager(_endPointID, _changeDetectionStrategyMock);

            _comparison123 = Compare123;
        }
        public void UnloadVirtualEndPoint_RealObjectEndPoint()
        {
            var objectEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "Customer");

            EnsureEndPointLoadedAndComplete(objectEndPointID);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, objectEndPointID);
        }
Beispiel #5
0
        private LoadedObjectDataWithDataSourceData CreateFetchedComputerData(Computer fetchedObject, ObjectID EmployeeID)
        {
            var endPointID           = RelationEndPointObjectMother.CreateRelationEndPointID(fetchedObject.ID, "Employee");
            var loadedObjectDataStub = LoadedObjectDataObjectMother.CreateLoadedObjectDataStub(fetchedObject);
            var dataContainer        = RelationEndPointTestHelper.CreateExistingForeignKeyDataContainer(endPointID, EmployeeID);

            return(new LoadedObjectDataWithDataSourceData(loadedObjectDataStub, dataContainer));
        }
        private LoadedObjectDataWithDataSourceData CreateFetchedOrderData(Order fetchedObject, ObjectID orderID)
        {
            var endPointID           = RelationEndPointObjectMother.CreateRelationEndPointID(fetchedObject.ID, "Customer");
            var loadedObjectDataStub = LoadedObjectDataObjectMother.CreateLoadedObjectDataStub(fetchedObject);
            var dataContainer        = RelationEndPointTestHelper.CreateExistingForeignKeyDataContainer(endPointID, orderID);

            return(new LoadedObjectDataWithDataSourceData(loadedObjectDataStub, dataContainer));
        }
Beispiel #7
0
        protected void CheckVirtualEndPointExistsAndComplete(DomainObject owningObject, string shortPropertyName, bool shouldEndPointExist, bool shouldDataBeComplete)
        {
            ArgumentUtility.CheckNotNull("owningObject", owningObject);
            ArgumentUtility.CheckNotNullOrEmpty("shortPropertyName", shortPropertyName);

            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(owningObject.ID, shortPropertyName);

            CheckVirtualEndPointExistsAndComplete(endPointID, shouldEndPointExist, shouldDataBeComplete);
        }
Beispiel #8
0
        protected void CheckEndPointExists(DomainObject owningObject, string shortPropertyName, bool endPointShouldExist)
        {
            ArgumentUtility.CheckNotNull("owningObject", owningObject);
            ArgumentUtility.CheckNotNullOrEmpty("shortPropertyName", shortPropertyName);

            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(owningObject.ID, shortPropertyName);

            CheckEndPointExists(endPointID, endPointShouldExist);
        }
        public void UnloadData_ChangedCollection()
        {
            DomainObjectIDs.OrderItem1.GetObject <OrderItem>().Order.OrderItems.Add(OrderItem.NewObject());
            Assert.That(TestableClientTransaction.DataManager.DataContainers[DomainObjectIDs.OrderItem1].State, Is.EqualTo(StateType.Unchanged));
            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderItems");

            Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID).HasChanged, Is.True);

            UnloadService.UnloadData(TestableClientTransaction, DomainObjectIDs.OrderItem1);
        }
        public void RelationEndPointBecomingIncomplete()
        {
            var relationEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(_domainObject.ID, "ParentClient");

            CheckLoggingMethod(
                () => _listener.RelationEndPointBecomingIncomplete(_clientTransaction, relationEndPointID),
                string.Format(
                    "{0} RelationEndPointBecomingIncomplete: {1}",
                    _clientTransaction.ID,
                    relationEndPointID));
        }
        public void UnloadVirtualEndPointAndItemData_DoesNothing_IfEndPointNotLoaded()
        {
            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders");

            Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID), Is.Null);

            ClientTransactionTestHelperWithMocks.EnsureTransactionThrowsOnEvents(TestableClientTransaction);

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, endPointID);

            Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID), Is.Null);
        }
Beispiel #12
0
        public override void SetUp()
        {
            base.SetUp();

            _transaction = new TestableClientTransaction();

            var id = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order).FullName + ".Customer");

            _endPoint = _transaction.ExecuteInScope(() => RelationEndPointObjectMother.CreateObjectEndPoint(id, null));

            _command = new RelationEndPointTouchCommand(_endPoint);
        }
Beispiel #13
0
        public void TransformToStandAlone()
        {
            var endPoint   = RelationEndPointObjectMother.CreateCollectionEndPoint_Customer1_Orders();
            var collection = endPoint.Collection;
            var originalCollectionDataStrategy = DomainObjectCollectionDataTestHelper.GetDataStrategy(collection);
            var originalCollectionContents     = collection.Cast <DomainObject> ().ToArray();

            var result = ((IAssociatableDomainObjectCollection)collection).TransformToStandAlone();

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order));
            Assert.That(collection, Is.EqualTo(originalCollectionContents));
            Assert.That(result, Is.SameAs(originalCollectionDataStrategy));
        }
Beispiel #14
0
        public override void SetUp()
        {
            base.SetUp();

            _domainObject     = DomainObjectIDs.Order1.GetObject <Order> ();
            _oldRelatedObject = DomainObjectIDs.OrderTicket1.GetObject <OrderTicket> ();
            _newRelatedObject = DomainObjectIDs.OrderTicket2.GetObject <OrderTicket> ();

            _endPointID = RelationEndPointID.Resolve(_domainObject, o => o.OrderTicket);
            _endPoint   = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _oldRelatedObject.ID);

            _command = new ObjectEndPointSetOneOneCommand(_endPoint, _newRelatedObject, OppositeObjectSetter, TransactionEventSinkWithMock);
        }
        public override void SetUp()
        {
            base.SetUp();

            _domainObject     = DomainObjectIDs.OrderItem1.GetObject <OrderItem>();
            _oldRelatedObject = _domainObject.Order;
            _newRelatedObject = DomainObjectIDs.Order3.GetObject <Order> ();

            _endPointID = RelationEndPointID.Resolve(_domainObject, oi => oi.Order);
            _endPoint   = (RealObjectEndPoint)RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _oldRelatedObject.ID);

            _command = new ObjectEndPointSetOneManyCommand(_endPoint, _newRelatedObject, OppositeObjectSetter, EndPointProviderStub, TransactionEventSinkWithMock);
        }
        public void SynchronizeOppositeEndPoint_NotInList()
        {
            var endPointStub = MockRepository.GenerateStub <IRealObjectEndPoint>();

            endPointStub
            .Stub(stub => stub.ID)
            .Return(RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.OrderItem1, "Order"));
            endPointStub
            .Stub(stub => stub.ObjectID)
            .Return(DomainObjectIDs.OrderItem1);

            _loadState.SynchronizeOppositeEndPoint(_virtualEndPointMock, endPointStub);
        }
Beispiel #17
0
        public override void SetUp()
        {
            base.SetUp();

            _domainObject  = DomainObjectIDs.Computer1.GetObject <Computer> ();
            _relatedObject = DomainObjectIDs.Employee3.GetObject <Employee> ();

            _endPointID = RelationEndPointID.Resolve(_domainObject, c => c.Employee);
            _endPoint   = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _relatedObject.ID);
            _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();

            _command = new ObjectEndPointSetSameCommand(_endPoint, _transactionEventSinkWithMock);
        }
        public override void SetUp()
        {
            base.SetUp();

            _domainObject     = DomainObjectIDs.Client3.GetObject <Client> ();
            _oldRelatedObject = DomainObjectIDs.Client1.GetObject <Client> ();
            _newRelatedObject = DomainObjectIDs.Client2.GetObject <Client> ();

            _endPointID = RelationEndPointID.Resolve(_domainObject, c => c.ParentClient);
            _endPoint   = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _oldRelatedObject.ID);

            _command = new ObjectEndPointSetUnidirectionalCommand(_endPoint, _newRelatedObject, OppositeObjectSetter, TransactionEventSinkWithMock);
        }
        private void CheckEndPointExists(ClientTransaction clientTransaction, DomainObject owningObject, string shortPropertyName, bool endPointShouldExist)
        {
            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(owningObject.ID, shortPropertyName);
            var endPoint   = ClientTransactionTestHelper.GetDataManager(clientTransaction).GetRelationEndPointWithoutLoading(endPointID);

            if (endPointShouldExist)
            {
                Assert.That(endPoint, Is.Not.Null, "End point '{0}' does not exist.", endPointID);
            }
            else
            {
                Assert.That(endPoint, Is.Null, "End point '{0}' should not exist.", endPointID);
            }
        }
        public void CreateDeleteCommand_NonVirtualOpposite()
        {
            var virtualDefinition = RelationEndPointObjectMother.GetEndPointDefinition(typeof(Order), "OrderTicket");

            _endPointMock.Stub(stub => stub.GetDomainObject()).Return(_order);
            _endPointMock.Stub(stub => stub.IsNull).Return(false);
            _endPointMock.Stub(stub => stub.Definition).Return(virtualDefinition);
            _endPointMock.Replay();

            var command = (RelationEndPointModificationCommand)_state.CreateDeleteCommand(_endPointMock, _fakeNullSetter);

            Assert.That(command, Is.TypeOf(typeof(ObjectEndPointDeleteCommand)));
            Assert.That(command.DomainObject, Is.SameAs(_order));
            Assert.That(command.ModifiedEndPoint, Is.SameAs(_endPointMock));
            Assert.That(GetOppositeObjectNullSetter((ObjectEndPointDeleteCommand)command), Is.SameAs(_fakeNullSetter));
        }
        public override void SetUp()
        {
            base.SetUp();

            _endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderTicket");

            _dataManager = new VirtualObjectEndPointDataManager(_endPointID);

            _oppositeObject       = DomainObjectMother.CreateFakeObject <OrderTicket> (DomainObjectIDs.OrderTicket1);
            _oppositeEndPointStub = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _oppositeEndPointStub.Stub(stub => stub.GetDomainObjectReference()).Return(_oppositeObject);

            _oppositeObject2       = DomainObjectMother.CreateFakeObject <OrderTicket> (DomainObjectIDs.OrderTicket2);
            _oppositeEndPointStub2 = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _oppositeEndPointStub2.Stub(stub => stub.GetDomainObjectReference()).Return(_oppositeObject2);
        }
        public void RelationEndPointMapUnregistering()
        {
            RelationEndPointID relationEndPointID;

            using (_clientTransaction.EnterNonDiscardingScope())
            {
                relationEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(_domainObject.ID, "ParentClient");
            }

            CheckLoggingMethod(
                () => _listener.RelationEndPointMapUnregistering(_clientTransaction, relationEndPointID),
                string.Format(
                    "{0} RelationEndPointMapUnregistering: {1}",
                    _clientTransaction.ID,
                    relationEndPointID));
        }
        public void GetOrLoadRelatedObject()
        {
            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order4, "OrderTicket");

            _persistenceStrategyMock
            .Expect(mock => mock.ResolveObjectRelationData(endPointID, _loadedObjectDataProviderStub))
            .Return(_loadedObjectDataStub1);
            _loadedObjectDataRegistrationAgentMock
            .Expect(mock => mock.RegisterIfRequired(new[] { _loadedObjectDataStub1 }, true));
            _mockRepository.ReplayAll();

            var result = _objectLoader.GetOrLoadRelatedObject(endPointID);

            _mockRepository.VerifyAll();
            Assert.That(result, Is.SameAs(_loadedObjectDataStub1));
        }
Beispiel #24
0
        public void PersistData_EndPoints()
        {
            var domainObject           = DomainObjectMother.CreateFakeObject <Order> ();
            var persistedDataContainer = DataContainerObjectMother.CreateExisting(domainObject);
            var persistedEndPoint1     = RelationEndPointObjectMother.CreateStub();

            persistedEndPoint1.Stub(stub => stub.HasChanged).Return(true);
            var persistedEndPoint2 = RelationEndPointObjectMother.CreateStub();

            persistedEndPoint2.Stub(stub => stub.HasChanged).Return(false);
            var persistedEndPoint3 = RelationEndPointObjectMother.CreateStub();

            persistedEndPoint3.Stub(stub => stub.HasChanged).Return(true);
            var persistableData = new PersistableData(
                domainObject, StateType.Changed, persistedDataContainer, new[] { persistedEndPoint1, persistedEndPoint2, persistedEndPoint3 });

            var counter = new OrderedExpectationCounter();

            _parentTransactionContextMock.Expect(mock => mock.UnlockParentTransaction()).Return(_unlockedParentTransactionContextMock);

            var parentEndPointMock1 = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            _parentTransactionContextMock
            .Expect(mock => mock.GetRelationEndPointWithoutLoading(persistedEndPoint1.ID))
            .Return(parentEndPointMock1);
            parentEndPointMock1
            .Expect(mock => mock.SetDataFromSubTransaction(persistedEndPoint1))
            .Ordered(counter, "SetDataFromSubTransaction must occur prior to Dispose.");

            var parentEndPointMock3 = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            _parentTransactionContextMock
            .Expect(mock => mock.GetRelationEndPointWithoutLoading(persistedEndPoint3.ID))
            .Return(parentEndPointMock3);
            parentEndPointMock3
            .Expect(mock => mock.SetDataFromSubTransaction(persistedEndPoint3))
            .Ordered(counter, "SetDataFromSubTransaction must occur prior to Dispose.");

            _unlockedParentTransactionContextMock.Expect(mock => mock.Dispose()).Ordered(counter, "Dispose should come at the end.");

            _persistenceStrategy.PersistData(new[] { persistableData }.AsOneTime());

            _parentTransactionContextMock.VerifyAllExpectations();
            _unlockedParentTransactionContextMock.VerifyAllExpectations();
            parentEndPointMock1.VerifyAllExpectations();
            parentEndPointMock3.VerifyAllExpectations();
        }
Beispiel #25
0
        public void PersistData_NewDataContainer_WithEndPoint()
        {
            var domainObject           = DomainObjectMother.CreateFakeObject <Order> ();
            var persistedDataContainer = DataContainerObjectMother.CreateNew(domainObject);

            SetPropertyValue(persistedDataContainer, typeof(Order), "OrderNumber", 12);
            var persistedEndPoint = RelationEndPointObjectMother.CreateStub();

            persistedEndPoint.Stub(stub => stub.HasChanged).Return(true);
            var persistableData = new PersistableData(domainObject, StateType.New, persistedDataContainer, new[] { persistedEndPoint });

            var counter = new OrderedExpectationCounter();

            _parentTransactionContextMock.Expect(mock => mock.UnlockParentTransaction()).Return(_unlockedParentTransactionContextMock);

            _parentTransactionContextMock.Stub(stub => stub.IsInvalid(domainObject.ID)).Return(true);
            _parentTransactionContextMock.Stub(stub => stub.GetDataContainerWithoutLoading(domainObject.ID)).Return(null);
            _unlockedParentTransactionContextMock
            .Expect(mock => mock.MarkNotInvalid(domainObject.ID))
            .Ordered(counter);
            _unlockedParentTransactionContextMock
            .Expect(mock => mock.RegisterDataContainer(Arg <DataContainer> .Is.Anything))
            .WhenCalledOrdered(
                counter,
                mi => CheckDataContainer((DataContainer)mi.Arguments[0], domainObject, null, StateType.New, _orderNumberPropertyDefinition, 12, 0, true),
                "New DataContainers must be registered before the parent relation end-points are retrieved for persistence (and prior to Dispose)."
                );

            var parentEndPointMock = MockRepository.GenerateStrictMock <IRelationEndPoint>();

            _parentTransactionContextMock
            .Expect(mock => mock.GetRelationEndPointWithoutLoading(persistedEndPoint.ID))
            .Return(parentEndPointMock)
            .Ordered(counter, "New DataContainers must be registered before the parent relation end-points are retrieved for persistence.");
            parentEndPointMock
            .Expect(mock => mock.SetDataFromSubTransaction(persistedEndPoint))
            .Ordered(counter, "SetDataFromSubTransaction must occur prior to Dispose.");

            _unlockedParentTransactionContextMock.Expect(mock => mock.Dispose()).Ordered(counter, "Dispose should come at the end.");

            _persistenceStrategy.PersistData(new[] { persistableData }.AsOneTime());

            _parentTransactionContextMock.VerifyAllExpectations();
            _unlockedParentTransactionContextMock.VerifyAllExpectations();
            parentEndPointMock.VerifyAllExpectations();
        }
        public override void SetUp()
        {
            base.SetUp();

            _endPointID   = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderTicket");
            _endPoint     = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, DomainObjectIDs.OrderTicket1);
            _domainObject = _endPoint.GetDomainObject();

            _oppositeObjectNullSetterCalled = false;
            _oppositeObjectNullSetter       = () =>
            {
                _oppositeObjectNullSetterCalled = true;
            };

            _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();
            _command = new ObjectEndPointDeleteCommand(_endPoint, _oppositeObjectNullSetter, _transactionEventSinkWithMock);
        }
        public void VirtualRelationEndPointStateUpdated()
        {
            RelationEndPointID relationEndPointID;

            using (_clientTransaction.EnterNonDiscardingScope())
            {
                relationEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(_domainObject.ID, "ParentClient");
            }

            CheckLoggingMethod(
                () => _listener.VirtualRelationEndPointStateUpdated(_clientTransaction, relationEndPointID, false),
                string.Format(
                    "{0} VirtualRelationEndPointStateUpdated: {1} {2}",
                    _clientTransaction.ID,
                    relationEndPointID,
                    false));
        }
Beispiel #28
0
        public void PersistData_DeletedDataContainer_WithEndPoint_ExistingInParent()
        {
            var domainObject           = DomainObjectMother.CreateFakeObject <Order> ();
            var persistedDataContainer = DataContainerObjectMother.CreateDeleted(domainObject);
            var persistedEndPoint      = RelationEndPointObjectMother.CreateStub();

            persistedEndPoint.Stub(stub => stub.HasChanged).Return(true);
            var persistableData = new PersistableData(domainObject, StateType.Deleted, persistedDataContainer, new[] { persistedEndPoint });

            _parentTransactionContextMock.Expect(mock => mock.UnlockParentTransaction()).Return(_unlockedParentTransactionContextMock);

            var counter = new OrderedExpectationCounter();

            var parentEndPointMock = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            _parentTransactionContextMock
            .Expect(mock => mock.GetRelationEndPointWithoutLoading(persistedEndPoint.ID))
            .Return(parentEndPointMock);
            parentEndPointMock
            .Expect(mock => mock.SetDataFromSubTransaction(persistedEndPoint))
            .Ordered(counter, "SetDataFromSubTransaction must occur prior to Dispose.");

            var parentDataContainer = DataContainerObjectMother.CreateExisting(persistedDataContainer.ID);

            parentDataContainer.SetDomainObject(domainObject);
            _parentTransactionContextMock
            .Stub(stub => stub.GetDataContainerWithoutLoading(domainObject.ID))
            .Return(parentDataContainer);

            _unlockedParentTransactionContextMock
            .Expect(mock => mock.Dispose())
            .WhenCalledOrdered(
                counter,
                mi => Assert.That(
                    parentDataContainer.State,
                    Is.EqualTo(StateType.Deleted),
                    "Parent DataContainer must be deleted before parent transaction is locked again."),
                "Dispose should come at the end.");

            _persistenceStrategy.PersistData(new[] { persistableData }.AsOneTime());

            _parentTransactionContextMock.VerifyAllExpectations();
            _unlockedParentTransactionContextMock.VerifyAllExpectations();
            parentEndPointMock.VerifyAllExpectations();
        }
Beispiel #29
0
        public void PersistData_DeletedDataContainer_WithEndPoint_NewInParent()
        {
            var domainObject           = DomainObjectMother.CreateFakeObject <Order> ();
            var persistedDataContainer = DataContainerObjectMother.CreateDeleted(domainObject);
            var persistedEndPoint      = RelationEndPointObjectMother.CreateStub();

            persistedEndPoint.Stub(stub => stub.HasChanged).Return(true);
            var persistableData = new PersistableData(domainObject, StateType.Deleted, persistedDataContainer, new[] { persistedEndPoint });

            var counter = new OrderedExpectationCounter();

            _parentTransactionContextMock.Expect(mock => mock.UnlockParentTransaction()).Return(_unlockedParentTransactionContextMock);

            var parentEndPointMock = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            _parentTransactionContextMock
            .Expect(mock => mock.GetRelationEndPointWithoutLoading(persistedEndPoint.ID))
            .Return(parentEndPointMock)
            .Ordered(counter, "Deleted DataContainers must be persisted after the parent relation end-points are retrieved for persistence.");
            parentEndPointMock
            .Expect(mock => mock.SetDataFromSubTransaction(persistedEndPoint))
            .Ordered(counter, "SetDataFromSubTransaction must occur prior to Dispose.");

            var parentDataContainer = DataContainerObjectMother.CreateNew(persistedDataContainer.ID);

            parentDataContainer.SetDomainObject(domainObject);
            _parentTransactionContextMock
            .Stub(stub => stub.GetDataContainerWithoutLoading(domainObject.ID))
            .Return(parentDataContainer);

            _unlockedParentTransactionContextMock
            .Expect(mock => mock.Discard(parentDataContainer))
            .Ordered(counter, "Deleted DataContainers must be persisted after the parent relation end-points are retrieved for persistence.");

            _unlockedParentTransactionContextMock
            .Expect(mock => mock.Dispose())
            .Ordered(counter, "Dispose should come at the end.");

            _persistenceStrategy.PersistData(new[] { persistableData }.AsOneTime());

            _parentTransactionContextMock.VerifyAllExpectations();
            _unlockedParentTransactionContextMock.VerifyAllExpectations();
            parentEndPointMock.VerifyAllExpectations();
        }
Beispiel #30
0
        public void ExpandToAllRelatedObjects()
        {
            var insertedEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(_insertedRelatedObject.ID, "Customer");
            var insertedEndPoint   = (IObjectEndPoint)DataManager.GetRelationEndPointWithoutLoading(insertedEndPointID);

            Assert.That(insertedEndPoint, Is.Not.Null);

            EndPointProviderStub.Stub(stub => stub.GetRelationEndPointWithLazyLoad(insertedEndPoint.ID)).Return(insertedEndPoint);

            var oldCustomer = _insertedRelatedObject.Customer;
            var oldRelatedEndPointOfInsertedObject = DataManager.GetRelationEndPointWithoutLoading(RelationEndPointID.Resolve(oldCustomer, c => c.Orders));

            EndPointProviderStub
            .Stub(stub => stub.GetRelationEndPointWithLazyLoad(oldRelatedEndPointOfInsertedObject.ID))
            .Return(oldRelatedEndPointOfInsertedObject);

            var bidirectionalModification = _command.ExpandToAllRelatedObjects();

            // DomainObject.Orders.Insert (_insertedRelatedObject, 12)
            var steps = bidirectionalModification.GetNestedCommands();

            Assert.That(steps.Count, Is.EqualTo(3));

            // _insertedRelatedObject.Customer = DomainObject (previously oldCustomer)
            Assert.That(steps[0], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator)));
            var setCustomerCommand = ((ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[0]).DecoratedCommand);

            Assert.That(setCustomerCommand.ModifiedEndPoint, Is.SameAs(insertedEndPoint));
            Assert.That(setCustomerCommand.OldRelatedObject, Is.SameAs(oldCustomer));
            Assert.That(setCustomerCommand.NewRelatedObject, Is.SameAs(DomainObject));

            // DomainObject.Orders.Insert (_insertedRelatedObject, 12)
            Assert.That(steps[1], Is.SameAs(_command));

            // oldCustomer.Orders.Remove (_insertedRelatedObject)
            Assert.That(steps[2], Is.TypeOf <VirtualEndPointStateUpdatedRaisingCommandDecorator> ());
            var oldCustomerOrdersRemoveCommand = ((CollectionEndPointRemoveCommand)((VirtualEndPointStateUpdatedRaisingCommandDecorator)steps[2]).DecoratedCommand);

            Assert.That(oldCustomerOrdersRemoveCommand.ModifiedEndPoint, Is.SameAs(((StateUpdateRaisingCollectionEndPointDecorator)oldRelatedEndPointOfInsertedObject).InnerEndPoint));
            Assert.That(oldCustomerOrdersRemoveCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(oldCustomer.ID));
            Assert.That(oldCustomerOrdersRemoveCommand.OldRelatedObject, Is.SameAs(_insertedRelatedObject));
        }