Example #1
0
        public void EndRegisterIfRequired_RaisesEndEvent_EvenWhenRegistrationThrows()
        {
            var dataContainer1 = DataContainerObjectMother.Create(DomainObjectIDs.Order1);
            var dataContainer2 = DataContainerObjectMother.Create(DomainObjectIDs.Order3);
            var collector      = CreateCollectorAndPrepare(dataContainer1, dataContainer2);

            var exception = new Exception("Test");

            using (_mockRepository.Ordered())
            {
                var loadedObjectIDs = new[] { dataContainer1.ID, dataContainer2.ID };
                _registrationListenerMock.Expect(mock => mock.OnBeforeObjectRegistration(Arg <ReadOnlyCollection <ObjectID> > .List.Equal(loadedObjectIDs)));

                _dataManagerMock.Expect(mock => mock.RegisterDataContainer(dataContainer1));
                _dataManagerMock.Expect(mock => mock.RegisterDataContainer(dataContainer2)).Throw(exception);

                _registrationListenerMock
                .Expect(mock => mock.OnAfterObjectRegistration(
                            Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { dataContainer1.ID, dataContainer2.ID }),
                            Arg <ReadOnlyCollection <DomainObject> > .List.Equal(new[] { dataContainer1.DomainObject })));
            }
            _mockRepository.ReplayAll();

            Assert.That(() => _agent.EndRegisterIfRequired(collector), Throws.Exception.SameAs(exception));

            _mockRepository.VerifyAll();
        }
Example #2
0
        public override void SetUp()
        {
            base.SetUp();

            _transaction       = ClientTransactionObjectMother.Create();
            _eventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();
            _invalidDomainObjectManagerMock = MockRepository.GenerateStrictMock <IInvalidDomainObjectManager> ();
            _dataManagerMock = MockRepository.GenerateStrictMock <IDataManager> ();
            _enlistedDomainObjectManagerMock = MockRepository.GenerateStrictMock <IEnlistedDomainObjectManager> ();
            _persistenceStrategyMock         = MockRepository.GenerateStrictMock <IPersistenceStrategy>();

            _agent = new ObjectLifetimeAgent(
                _transaction,
                _eventSinkWithMock,
                _invalidDomainObjectManagerMock,
                _dataManagerMock,
                _enlistedDomainObjectManagerMock,
                _persistenceStrategyMock);

            _objectID1      = DomainObjectIDs.Order1;
            _domainObject1  = DomainObjectMother.CreateFakeObject(_objectID1);
            _dataContainer1 = DataContainerObjectMother.CreateExisting(_domainObject1);

            _objectID2      = DomainObjectIDs.Order3;
            _domainObject2  = DomainObjectMother.CreateFakeObject(_objectID2);
            _dataContainer2 = DataContainerObjectMother.CreateExisting(_domainObject2);

            _domainObjectCreatorMock       = MockRepository.GenerateStrictMock <IDomainObjectCreator>();
            _typeDefinitionWithCreatorMock = ClassDefinitionObjectMother.CreateClassDefinitionWithTable(
                TestDomainStorageProviderDefinition,
                classType: typeof(OrderItem),
                instanceCreator: _domainObjectCreatorMock);

            _objectIDWithCreatorMock = new ObjectID(_typeDefinitionWithCreatorMock, Guid.NewGuid());
        }
Example #3
0
        public void EndRegisterIfRequired_RegistersDataContainers_AndRaisesEvents()
        {
            var dataContainer1 = DataContainerObjectMother.Create(DomainObjectIDs.Order1);
            var dataContainer2 = DataContainerObjectMother.Create(DomainObjectIDs.Order3);
            var collector      = CreateCollectorAndPrepare(dataContainer1, dataContainer2);

            using (_mockRepository.Ordered())
            {
                var loadedObjectIDs = new[] { dataContainer1.ID, dataContainer2.ID };
                _registrationListenerMock.Expect(mock => mock.OnBeforeObjectRegistration(Arg <ReadOnlyCollection <ObjectID> > .List.Equal(loadedObjectIDs)));

                _dataManagerMock.Expect(mock => mock.RegisterDataContainer(dataContainer1));
                _dataManagerMock.Expect(mock => mock.RegisterDataContainer(dataContainer2));

                _registrationListenerMock
                .Expect(mock => mock.OnAfterObjectRegistration(
                            Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { dataContainer1.ID, dataContainer2.ID }),
                            Arg <ReadOnlyCollection <DomainObject> > .List.Equal(new[] { dataContainer1.DomainObject, dataContainer2.DomainObject })));
            }
            _mockRepository.ReplayAll();

            _agent.EndRegisterIfRequired(collector);

            _mockRepository.VerifyAll();
        }
Example #4
0
        public void PersistData_ChangedDataContainer()
        {
            var persistableData = CreatePersistableDataForExistingOrder();

            persistableData.DataContainer.SetTimestamp(1676);
            SetPropertyValue(persistableData.DataContainer, typeof(Order), "OrderNumber", 12);
            Assert.That(persistableData.DataContainer.State, Is.EqualTo(StateType.Changed));

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

            var parentDataContainer = DataContainerObjectMother.CreateExisting(persistableData.DomainObject);

            parentDataContainer.SetTimestamp(4711);
            Assert.That(parentDataContainer.State, Is.EqualTo(StateType.Unchanged));
            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithoutLoading(persistableData.DomainObject.ID))
            .Return(parentDataContainer);

            _unlockedParentTransactionContextMock
            .Expect(mock => mock.Dispose())
            .WhenCalled(mi =>
            {
                Assert.That(parentDataContainer.Timestamp, Is.EqualTo(1676), "ParentDataContainer must be changed prior to Dispose.");
                Assert.That(GetPropertyValue(parentDataContainer, typeof(Order), "OrderNumber"), Is.EqualTo(12));
                Assert.That(parentDataContainer.State, Is.EqualTo(StateType.Changed));
                Assert.That(parentDataContainer.HasBeenMarkedChanged, Is.False);
            });

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

            _parentTransactionContextMock.VerifyAllExpectations();
            _unlockedParentTransactionContextMock.VerifyAllExpectations();
        }
        public void DataContainerStateUpdated_AllowedForActiveTransaction_NotInLoadMode()
        {
            Assert.That(_listener.IsInLoadMode, Is.False);
            var someDataContainer = DataContainerObjectMother.Create(DomainObjectIDs.Client1);

            Assert.That(() => _listener.DataContainerStateUpdated(_transaction, someDataContainer, StateType.Changed), Throws.Nothing);
        }
Example #6
0
        public override void SetUp()
        {
            base.SetUp();

            _mockRepository = new MockRepository();

            _eventSinkWithMock       = _mockRepository.StrictMock <IClientTransactionEventSink>();
            _persistenceStrategyMock = _mockRepository.StrictMock <IPersistenceStrategy> ();
            _dataManagerMock         = _mockRepository.StrictMock <IDataManager> ();
            _clientTransaction       = ClientTransactionObjectMother.Create();

            _agent = new CommitRollbackAgent(_clientTransaction, _eventSinkWithMock, _persistenceStrategyMock, _dataManagerMock);

            _fakeChangedDomainObject = LifetimeService.NewObject(_clientTransaction, typeof(Order), ParamList.Empty);
            _fakeNewDomainObject     = LifetimeService.NewObject(_clientTransaction, typeof(Order), ParamList.Empty);
            _fakeDeletedDomainObject = LifetimeService.NewObject(_clientTransaction, typeof(Order), ParamList.Empty);

            var fakeDataContainer1 = DataContainerObjectMother.Create();
            var fakeDataContainer2 = DataContainerObjectMother.Create();
            var fakeDataContainer3 = DataContainerObjectMother.Create();

            _fakeChangedPersistableItem = new PersistableData(_fakeChangedDomainObject, StateType.Changed, fakeDataContainer1, new IRelationEndPoint[0]);
            _fakeNewPersistableItem     = new PersistableData(_fakeNewDomainObject, StateType.New, fakeDataContainer2, new IRelationEndPoint[0]);
            _fakeDeletedPersistableItem = new PersistableData(_fakeDeletedDomainObject, StateType.Deleted, fakeDataContainer3, new IRelationEndPoint[0]);
        }
Example #7
0
        private PersistableData CreatePersistableDataForExistingOrder()
        {
            var domainObject  = DomainObjectMother.CreateFakeObject <Order> ();
            var dataContainer = DataContainerObjectMother.CreateExisting(domainObject.ID);

            dataContainer.SetDomainObject(domainObject);
            return(new PersistableData(domainObject, StateType.Changed, dataContainer, new IRelationEndPoint[0]));
        }
Example #8
0
        public void RaiseDataContainerMapUnregisteringEvent()
        {
            var dataContainer = DataContainerObjectMother.Create(Order.NewObject());

            CheckEventWithListenersOnly(
                s => s.RaiseDataContainerMapUnregisteringEvent(dataContainer),
                l => l.DataContainerMapUnregistering(_clientTransaction, dataContainer));
        }
Example #9
0
        private DataContainer CreateChangedDataContainer(
            ObjectID objectID, int timestamp, PropertyDefinition propertyDefinition, object currentPropertyValue)
        {
            var parentDataContainer = DataContainerObjectMother.CreateExisting(objectID);

            parentDataContainer.SetTimestamp(timestamp);
            parentDataContainer.SetValue(propertyDefinition, currentPropertyValue);
            return(parentDataContainer);
        }
Example #10
0
        public void RaiseDataContainerStateUpdatedEvent()
        {
            var dataContainer         = DataContainerObjectMother.Create(Order.NewObject());
            var newDataContainerState = StateType.New;

            CheckEventWithListenersOnly(
                s => s.RaiseDataContainerStateUpdatedEvent(dataContainer, newDataContainerState),
                l => l.DataContainerStateUpdated(_clientTransaction, dataContainer, newDataContainerState));
        }
        public void DataContainerStateUpdated_ForbiddenWhenTransactionReadOnly()
        {
            ClientTransactionTestHelper.SetIsWriteable(_transaction, false);
            Assert.That(_listener.IsInLoadMode, Is.False);
            var someDataContainer = DataContainerObjectMother.Create(DomainObjectIDs.Client1);

            Assert.That(
                () => _listener.DataContainerStateUpdated(_transaction, someDataContainer, StateType.Changed),
                Throws.TypeOf <ClientTransactionReadOnlyException> ());
        }
Example #12
0
        public override void SetUp()
        {
            base.SetUp();

            _commandStub      = MockRepository.GenerateStub <IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> >();
            _executionContext = MockRepository.GenerateStub <IRdbmsProviderCommandExecutionContext>();

            _order1Container = DataContainerObjectMother.Create(DomainObjectIDs.Order1);
            _order2Container = DataContainerObjectMother.Create(DomainObjectIDs.Order3);
            _order3Container = DataContainerObjectMother.Create(DomainObjectIDs.Order4);
        }
        public void DataContainerStateUpdated_LoadedObject_AllowedInLoadMode()
        {
            ClientTransactionTestHelper.SetIsWriteable(_transaction, false);

            _listener.AddCurrentlyLoadingObjectIDs(new[] { DomainObjectIDs.Client1 });
            Assert.That(_listener.IsInLoadMode, Is.True);

            var someDataContainer = DataContainerObjectMother.Create(DomainObjectIDs.Client1);

            Assert.That(() => _listener.DataContainerStateUpdated(_transaction, someDataContainer, StateType.Changed), Throws.Nothing);
        }
Example #14
0
        public void GetObject_DeletedObject_IncludeDeletedTrue()
        {
            var dataContainer = DataContainerObjectMother.CreateDeleted(_domainObject1);

            Assert.That(dataContainer.State, Is.EqualTo(StateType.Deleted));

            _dataManagerMock.Stub(stub => stub.GetDataContainerWithLazyLoad(_objectID1, true)).Return(dataContainer);

            var result = _agent.GetObject(_objectID1, true);

            Assert.That(result, Is.SameAs(dataContainer.DomainObject));
        }
Example #15
0
        public void Execute_NonMatchingDataContainer()
        {
            var dataContainer = DataContainerObjectMother.Create(DomainObjectIDs.Order3);

            _innerCommandMock.Expect(mock => mock.Execute(_fakeContext)).Return(dataContainer);

            Assert.That(
                () => _associateCommand.Execute(_fakeContext),
                Throws.TypeOf <PersistenceException> ().With.Message.EqualTo(
                    "The ObjectID of the loaded DataContainer 'Order|83445473-844a-4d3f-a8c3-c27f8d98e8ba|System.Guid' and the expected ObjectID "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' differ."));
        }
Example #16
0
        public void GetObject_DeletedObject_IncludeDeletedFalse()
        {
            var dataContainer = DataContainerObjectMother.CreateDeleted(_domainObject1);

            Assert.That(dataContainer.State, Is.EqualTo(StateType.Deleted));

            _dataManagerMock.Stub(stub => stub.GetDataContainerWithLazyLoad(_objectID1, true)).Return(dataContainer);

            Assert.That(
                () => _agent.GetObject(_objectID1, false),
                Throws.TypeOf <ObjectDeletedException>().With.Property <ObjectDeletedException> (e => e.ID).EqualTo(_objectID1));
        }
Example #17
0
        public void Execute_MatchingDataContainer()
        {
            var dataContainer = DataContainerObjectMother.Create(_expectedID);

            _innerCommandMock.Expect(mock => mock.Execute(_fakeContext)).Return(dataContainer);

            var result = _associateCommand.Execute(_fakeContext);

            _innerCommandMock.VerifyAllExpectations();
            Assert.That(result.ObjectID, Is.EqualTo(_expectedID));
            Assert.That(result.LocatedObject, Is.SameAs(dataContainer));
        }
        public void DataContainerStateUpdated_SomeObject_ForbiddenInLoadMode()
        {
            ClientTransactionTestHelper.SetIsWriteable(_transaction, false);

            _listener.AddCurrentlyLoadingObjectIDs(new[] { DomainObjectIDs.Client1 });
            Assert.That(_listener.IsInLoadMode, Is.True);

            var someDataContainer = DataContainerObjectMother.Create(DomainObjectIDs.Client2);

            Assert.That(
                () => _listener.DataContainerStateUpdated(_transaction, someDataContainer, StateType.Changed),
                Throws.TypeOf <ClientTransactionReadOnlyException>());
        }
Example #19
0
        public void Execute_DuplicatedDataContainer()
        {
            var command = new MultiDataContainerAssociateWithIDsCommand(new[] { DomainObjectIDs.Order1 }, _commandStub);

            var otherOrder1DataContainer = DataContainerObjectMother.Create(_order1Container.ID);

            _commandStub.Stub(stub => stub.Execute(_executionContext)).Return(new[] { _order1Container, otherOrder1DataContainer });

            var result = command.Execute(_executionContext).ToList();

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0].LocatedObject, Is.SameAs(otherOrder1DataContainer));
            Assert.That(result[0].ObjectID, Is.EqualTo(DomainObjectIDs.Order1));
        }
Example #20
0
        public void LoadObjectData_Multiple()
        {
            var objectID1 = DomainObjectIDs.Order1;
            var objectID2 = DomainObjectIDs.Order3;
            var objectID3 = DomainObjectIDs.Order4;

            var parentObject1        = DomainObjectMother.CreateFakeObject <Order> (objectID1);
            var parentDataContainer1 = CreateChangedDataContainer(objectID1, 4711, _orderNumberPropertyDefinition, 17);

            CheckDataContainer(parentDataContainer1, objectID1, 4711, StateType.Changed, _orderNumberPropertyDefinition, 17, 0, true);

            var parentObject3        = DomainObjectMother.CreateFakeObject <Order> (objectID3);
            var parentDataContainer3 = DataContainerObjectMother.CreateExisting(objectID3);

            var parentEventListenerMock = MockRepository.GenerateStrictMock <IDataContainerEventListener> ();

            parentDataContainer1.SetEventListener(parentEventListenerMock);
            parentDataContainer3.SetEventListener(parentEventListenerMock);

            // Use a strict mock because the parameter should not be enumerated, it should only be passed on TryGetObjects

            _parentTransactionContextMock
            .Expect(mock => mock.TryGetObjects(Arg <IEnumerable <ObjectID> > .List.Equal(new[] { objectID1, objectID2, objectID3 })))
            .Return(new[] { parentObject1, null, parentObject3 });
            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithLazyLoad(objectID1, true))
            .Return(parentDataContainer1);
            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithLazyLoad(objectID3, true))
            .Return(parentDataContainer3);

            var result = _persistenceStrategy.LoadObjectData(new[] { objectID1, objectID2, objectID3 }.AsOneTime()).ToList();

            _parentTransactionContextMock.VerifyAllExpectations();
            parentEventListenerMock.AssertWasNotCalled(
                mock => mock.PropertyValueReading(Arg <DataContainer> .Is.Anything, Arg <PropertyDefinition> .Is.Anything, Arg <ValueAccess> .Is.Anything));

            Assert.That(result[0], Is.TypeOf <FreshlyLoadedObjectData> ());
            Assert.That(result[0].ObjectID, Is.EqualTo(objectID1));
            CheckDataContainer(((FreshlyLoadedObjectData)result[0]).FreshlyLoadedDataContainer, objectID1, 4711, StateType.Unchanged, _orderNumberPropertyDefinition, 17, 17, false);

            Assert.That(result[1], Is.TypeOf <NotFoundLoadedObjectData> ());
            Assert.That(result[1].ObjectID, Is.EqualTo(objectID2));

            Assert.That(result[2], Is.TypeOf <FreshlyLoadedObjectData> ());
            Assert.That(result[2].ObjectID, Is.EqualTo(objectID3));
        }
Example #21
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();
        }
Example #22
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();
        }
Example #23
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();
        }
Example #24
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();
        }
Example #25
0
        public void LoadObjectData_Multiple_ParentObjectIsDeleted()
        {
            var objectID     = DomainObjectIDs.Order1;
            var parentObject = DomainObjectMother.CreateFakeObject <Order> ();
            var deletedParentDataContainer = DataContainerObjectMother.CreateDeleted(objectID);

            _parentTransactionContextMock
            .Expect(mock => mock.TryGetObject(objectID))
            .Return(parentObject);
            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithLazyLoad(objectID, true))
            .Return(deletedParentDataContainer);

            Assert.That(
                () => _persistenceStrategy.LoadObjectData(objectID),
                Throws.TypeOf <ObjectDeletedException> ().With.Message.EqualTo(
                    "Object 'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' is already deleted in the parent transaction."));

            _parentTransactionContextMock.VerifyAllExpectations();
        }
Example #26
0
        public void PersistData_MarkedAsChangedDataContainer()
        {
            var persistableData1 = CreateMarkAsChangedPersistableDataForOrder();
            var persistableData2 = CreateMarkAsChangedPersistableDataForOrder();
            var persistableData3 = CreateMarkAsChangedPersistableDataForOrder();

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

            var unchangedParentDataContainer = DataContainerObjectMother.CreateExisting(persistableData1.DomainObject);

            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithoutLoading(persistableData1.DomainObject.ID))
            .Return(unchangedParentDataContainer);

            var changedParentDataContainer = DataContainerObjectMother.CreateExisting(persistableData2.DomainObject);

            SetPropertyValue(changedParentDataContainer, typeof(Order), "OrderNumber", 23);
            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithoutLoading(persistableData2.DomainObject.ID))
            .Return(changedParentDataContainer);

            var newParentDataContainer = DataContainerObjectMother.CreateNew(persistableData3.DomainObject);

            _parentTransactionContextMock
            .Expect(mock => mock.GetDataContainerWithoutLoading(persistableData3.DomainObject.ID))
            .Return(newParentDataContainer);

            _unlockedParentTransactionContextMock
            .Expect(mock => mock.Dispose())
            .WhenCalled(mi =>
            {
                Assert.That(unchangedParentDataContainer.HasBeenMarkedChanged, Is.True);
                Assert.That(changedParentDataContainer.HasBeenMarkedChanged, Is.True);
                Assert.That(newParentDataContainer.HasBeenMarkedChanged, Is.False);
            });

            _persistenceStrategy.PersistData(new[] { persistableData1, persistableData2, persistableData3 }.AsOneTime());

            _parentTransactionContextMock.VerifyAllExpectations();
            _unlockedParentTransactionContextMock.VerifyAllExpectations();
        }
Example #27
0
 public static FreshlyLoadedObjectData CreateFreshlyLoadedObjectData(ObjectID objectID)
 {
     return(new FreshlyLoadedObjectData(DataContainerObjectMother.Create(objectID)));
 }
 public IMethodOptions <IEnumerable <ILoadedObjectData> > ExpectLoadObjectData(IEnumerable <ObjectID> loadedObjectIDs)
 {
     return(Mock
            .Expect(mock => mock.LoadObjectData(Arg <IEnumerable <ObjectID> > .List.Equal(loadedObjectIDs)))
            .Return(loadedObjectIDs.Select(id => (ILoadedObjectData) new FreshlyLoadedObjectData(DataContainerObjectMother.CreateExisting(id)))));
 }