Esempio n. 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 void ExpandToAllRelatedObjects()
        {
            // Scenario: orderItem.Order = newOrder;

            var oldRelatedEndPointID   = RelationEndPointID.Resolve(_oldRelatedObject, o => o.OrderItems);
            var oldRelatedEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>();

            var newRelatedEndPointID   = RelationEndPointID.Resolve(_newRelatedObject, o => o.OrderItems);
            var newRelatedEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>();

            EndPointProviderStub.Stub(stub => stub.GetRelationEndPointWithLazyLoad(oldRelatedEndPointID)).Return(oldRelatedEndPointMock);
            EndPointProviderStub.Stub(stub => stub.GetRelationEndPointWithLazyLoad(newRelatedEndPointID)).Return(newRelatedEndPointMock);


            // oldOrder.OrderItems.Remove (orderItem)
            var fakeRemoveCommand = MockRepository.GenerateStub <IDataManagementCommand>();

            fakeRemoveCommand.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]);
            oldRelatedEndPointMock.Expect(mock => mock.CreateRemoveCommand(_domainObject)).Return(fakeRemoveCommand);
            oldRelatedEndPointMock.Replay();

            // newOrder.OrderItems.Add (orderItem);
            var fakeAddCommand = MockRepository.GenerateStub <IDataManagementCommand>();

            fakeAddCommand.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]);
            newRelatedEndPointMock.Expect(mock => mock.CreateAddCommand(_domainObject)).Return(fakeAddCommand);
            newRelatedEndPointMock.Replay();

            var bidirectionalModification = _command.ExpandToAllRelatedObjects();

            oldRelatedEndPointMock.VerifyAllExpectations();
            newRelatedEndPointMock.VerifyAllExpectations();

            var steps = bidirectionalModification.GetNestedCommands();

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

            // orderItem.Order = newOrder;
            Assert.That(steps[0], Is.SameAs(_command));

            // newOrder.OrderItems.Add (orderItem);
            Assert.That(steps[1], Is.SameAs(fakeAddCommand));

            // oldOrder.OrderItems.Remove (orderItem)
            Assert.That(steps[2], Is.SameAs(fakeRemoveCommand));
        }
Esempio n. 3
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));
        }