Exemplo n.º 1
0
        public void GetObjectReference_KnownObject_Invalid_Works()
        {
            _invalidDomainObjectManagerMock.Expect(mock => mock.IsInvalid(_objectIDWithCreatorMock)).Return(true);
            _invalidDomainObjectManagerMock.Expect(mock => mock.GetInvalidObjectReference(_objectIDWithCreatorMock)).Return(_domainObject1);

            var result = _agent.GetObjectReference(_objectIDWithCreatorMock);

            _invalidDomainObjectManagerMock.VerifyAllExpectations();
            _domainObjectCreatorMock.AssertWasNotCalled(
                mock => mock.CreateObjectReference(Arg <IObjectInitializationContext> .Is.Anything, Arg <ClientTransaction> .Is.Anything));

            Assert.That(result, Is.SameAs(_domainObject1));
        }
Exemplo n.º 2
0
        public void GetObjectReference_UnknownObject_WithSubTransaction_PutsRootTransactionIntoContext()
        {
            var subTransaction = _transaction.CreateSubTransaction();
            var agent          = new ObjectLifetimeAgent(
                subTransaction,
                _eventSinkWithMock,
                _invalidDomainObjectManagerMock,
                _dataManagerMock,
                _enlistedDomainObjectManagerMock,
                _persistenceStrategyMock);

            _invalidDomainObjectManagerMock.Stub(stub => stub.IsInvalid(_objectIDWithCreatorMock)).Return(false);
            _enlistedDomainObjectManagerMock.Stub(stub => stub.GetEnlistedDomainObject(_objectIDWithCreatorMock)).Return(null);

            _domainObjectCreatorMock
            .Expect(mock => mock.CreateObjectReference(Arg <ObjectReferenceInitializationContext> .Is.TypeOf, Arg.Is(subTransaction)))
            .Return(_domainObject1)
            .WhenCalled(
                mi => CheckInitializationContext <ObjectReferenceInitializationContext> (mi.Arguments[0], _objectIDWithCreatorMock, _transaction));

            var result = agent.GetObjectReference(_objectIDWithCreatorMock);

            _domainObjectCreatorMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(_domainObject1));
        }