コード例 #1
0
        public void InactiveTransactionIsActivated_ForEvents_EvenWhenAlreadyCurrent()
        {
            var inactiveClientTransaction = ClientTransaction.CreateRootTransaction();

            using (inactiveClientTransaction.EnterNonDiscardingScope())
            {
                using (ClientTransactionTestHelper.MakeInactive(inactiveClientTransaction))
                {
                    var transactionEventReceiverMock = MockRepository.GenerateStrictMock <ClientTransactionMockEventReceiver> (inactiveClientTransaction);
                    transactionEventReceiverMock
                    .Expect(mock => mock.SubTransactionCreated(Arg <ClientTransaction> .Is.Anything, Arg <SubTransactionCreatedEventArgs> .Is.Anything))
                    .WhenCalled(
                        mi =>
                    {
                        Assert.That(ClientTransaction.Current, Is.SameAs(inactiveClientTransaction));
                        Assert.That(ClientTransaction.Current.ActiveTransaction, Is.SameAs(inactiveClientTransaction));
                    });

                    var eventBroker = new ClientTransactionEventBroker(inactiveClientTransaction);
                    eventBroker.RaiseSubTransactionCreatedEvent(ClientTransactionObjectMother.Create());

                    transactionEventReceiverMock.VerifyAllExpectations();
                }
            }
        }
        private ClientTransaction CreateFakeSubTransaction(ClientTransaction clientTransaction)
        {
            var fakeSubTransaction = ClientTransactionObjectMother.Create();

            ClientTransactionTestHelper.SetSubTransaction(clientTransaction, fakeSubTransaction);
            return(fakeSubTransaction);
        }
コード例 #3
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]);
        }
コード例 #4
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());
        }
コード例 #5
0
        public void CloneTransaction_ManualSet()
        {
            ClientTransaction cloneTransaction = ClientTransactionObjectMother.Create();

            _cloner.CloneTransaction = cloneTransaction;
            Assert.That(_cloner.CloneTransaction, Is.SameAs(cloneTransaction));
        }
コード例 #6
0
        public void CloneTransaction_Reset()
        {
            ClientTransaction cloneTransaction = ClientTransactionObjectMother.Create();

            _cloner.CloneTransaction = cloneTransaction;
            _cloner.CloneTransaction = null;
            Assert.That(_cloner.CloneTransaction, Is.SameAs(TestableClientTransaction));
        }
コード例 #7
0
        public void RaiseSubTransactionInitializeEvent()
        {
            var subTransaction = ClientTransactionObjectMother.Create();

            CheckEventWithListenersFirst(
                s => s.RaiseSubTransactionInitializeEvent(subTransaction),
                l => l.SubTransactionInitialize(_clientTransaction, subTransaction),
                x => x.SubTransactionInitialize(_clientTransaction, subTransaction));
        }
コード例 #8
0
        public void Leave_NullAttachedScope_NoExceptionThrown()
        {
            var scopedTransaction = ClientTransactionObjectMother.Create();

            var scope =
                (ClientTransactionScope)
                PrivateInvoke.CreateInstanceNonPublicCtor(typeof(ClientTransactionScope), scopedTransaction, AutoRollbackBehavior.None, null);

            Assert.That(() => scope.Leave(), Throws.Nothing);
        }
コード例 #9
0
        public void ActivateTransaction_TransactionNotFromHierarchy_Throws()
        {
            var unrelatedTransaction = ClientTransactionObjectMother.Create();

            Assert.That(
                () => _hierarchy.ActivateTransaction(unrelatedTransaction),
                Throws.ArgumentException.With.Message.EqualTo(
                    "The activated transaction must be from this ClientTransactionHierarchy.\r\nParameter name: clientTransaction"));

            Assert.That(_hierarchy.ActiveTransaction, Is.SameAs(_rootTransaction));
        }
        public override void SetUp()
        {
            base.SetUp();

            _listener    = new ReadOnlyClientTransactionListenerWithLoadRules();
            _transaction = ClientTransactionObjectMother.Create();

            _client1 = LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Client1);
            _order1  = LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order1);
            _orderNumberPropertyDefinition = GetPropertyDefinition(typeof(Order), "OrderNumber");
            _orderTicketEndPointDefinition = GetEndPointDefinition(typeof(Order), "OrderTicket");
        }
コード例 #11
0
        public override void SetUp()
        {
            base.SetUp();

            _clientTransaction = ClientTransactionObjectMother.Create();

            _mockRepository           = new MockRepository();
            _dataManagerMock          = _mockRepository.StrictMock <IDataManager> ();
            _registrationListenerMock = _mockRepository.StrictMock <ILoadedObjectDataRegistrationListener> ();

            _agent = new LoadedObjectDataRegistrationAgent(_clientTransaction, _dataManagerMock, _registrationListenerMock);
        }
コード例 #12
0
        public void AppendLeafTransaction_WithNotASubOfCurrentLeaf_Throws()
        {
            var unrelatedTransaction = ClientTransactionObjectMother.Create();

            Assert.That(
                () => _hierarchy.AppendLeafTransaction(unrelatedTransaction),
                Throws.ArgumentException.With.Message.EqualTo(
                    "The new LeafTransaction must have the previous LeafTransaction as its parent.\r\nParameter name: leafTransaction"));

            Assert.That(_hierarchy.RootTransaction, Is.SameAs(_rootTransaction));
            Assert.That(_hierarchy.LeafTransaction, Is.SameAs(_rootTransaction));
            Assert.That(_hierarchy.ActiveTransaction, Is.SameAs(_rootTransaction));
        }
コード例 #13
0
        public void Leave_ExecutesAttachedScope_AfterAutoDiscardBehavior()
        {
            var scopedTransaction = ClientTransactionObjectMother.Create();
            var attachedScopeMock = MockRepository.GenerateStrictMock <IDisposable> ();

            attachedScopeMock.Expect(mock => mock.Dispose()).WhenCalled(mock => Assert.That(scopedTransaction.IsDiscarded, Is.True));

            var scope = (ClientTransactionScope)PrivateInvoke.CreateInstanceNonPublicCtor(
                typeof(ClientTransactionScope), scopedTransaction, AutoRollbackBehavior.Discard, attachedScopeMock);

            scope.Leave();

            attachedScopeMock.VerifyAllExpectations();
        }
コード例 #14
0
        public void RaiseSubTransactionCreatedEvent()
        {
            var subTransaction = ClientTransactionObjectMother.Create();

            CheckEventWithListenersLast(
                s => s.RaiseSubTransactionCreatedEvent(subTransaction),
                l => l.SubTransactionCreated(_clientTransaction, subTransaction),
                x => x.SubTransactionCreated(_clientTransaction, subTransaction),
                () =>
                _transactionEventReceiverMock
                .Expect(
                    mock => mock.SubTransactionCreated(
                        Arg.Is(_clientTransaction),
                        Arg <SubTransactionCreatedEventArgs> .Matches(args => args.SubTransaction == subTransaction)))
                .WithCurrentTransaction(_clientTransaction));
        }
コード例 #15
0
        public void Serializable()
        {
            var instance = new TransactionHierarchyManager(
                ClientTransactionObjectMother.Create(),
                new SerializableClientTransactionEventSinkFake(),
                ClientTransactionObjectMother.Create(),
                new SerializableTransactionHierarchyManagerFake(),
                new SerializableClientTransactionEventSinkFake());
            var deserializedInstance = Serializer.SerializeAndDeserialize(instance);

            Assert.That(deserializedInstance.IsWriteable, Is.True);
            Assert.That(deserializedInstance.SubTransaction, Is.Null);
            Assert.That(deserializedInstance.ThisTransaction, Is.Not.Null);
            Assert.That(deserializedInstance.ParentTransaction, Is.Not.Null);
            Assert.That(deserializedInstance.ParentHierarchyManager, Is.Not.Null);
        }
コード例 #16
0
        public override void SetUp()
        {
            base.SetUp();

            _thisTransaction             = ClientTransactionObjectMother.Create();
            _thisEventSinkWithStrictMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();
            _hierarchyStrictMock         = MockRepository.GenerateStrictMock <IClientTransactionHierarchy>();

            _parentTransaction = ClientTransactionObjectMother.Create();
            _parentHierarchyManagerStrictMock = MockRepository.GenerateStrictMock <ITransactionHierarchyManager>();
            _parentHierarchyManagerStrictMock.Stub(stub => stub.TransactionHierarchy).Return(_hierarchyStrictMock);
            _parentEventSinkWithStrictMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();

            _manager = new TransactionHierarchyManager(
                _thisTransaction, _thisEventSinkWithStrictMock, _parentTransaction, _parentHierarchyManagerStrictMock, _parentEventSinkWithStrictMock);
            _managerWithoutParent = new TransactionHierarchyManager(_thisTransaction, _thisEventSinkWithStrictMock);
        }