Esempio n. 1
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));
        }
Esempio n. 2
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));
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
Esempio n. 5
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();
        }