예제 #1
0
        public void Test_WithParentTransactionStrategy()
        {
            var strategy        = CreateScopedTransactionStrategy(true, OuterTransactionStrategyMock);
            var expectedObjects = new[] { new object() };

            InvokeOnExecutionPlay(strategy);
            using (MockRepository.Ordered())
            {
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub));
                TransactionMock.Expect(mock => mock.Commit());

                ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(expectedObjects);
                OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(expectedObjects));

                ScopeMock.Expect(mock => mock.Leave());
                TransactionMock.Expect(mock => mock.Release());
            }

            MockRepository.ReplayAll();

            strategy.OnExecutionStop(Context, ExecutionListenerStub);

            MockRepository.VerifyAll();
            Assert.That(strategy.Scope, Is.Null);
        }
예제 #2
0
        public void Test_WithScope()
        {
            var object1 = new object();
            var object2 = new object();

            InvokeOnExecutionPlay(_strategy);
            TransactionMock.BackToRecord();
            TransactionFactoryMock.BackToRecord();
            var newScopeMock = MockRepository.StrictMock <ITransactionScope>();

            using (MockRepository.Ordered())
            {
                ScopeMock.Expect(mock => mock.Leave());
                TransactionMock.Expect(mock => mock.Release());
                TransactionFactoryMock.Expect(mock => mock.Create()).Return(_newTransactionMock);
                _newTransactionMock.Expect(mock => mock.EnterScope()).Return(newScopeMock);

                ExecutionContextMock.Expect(mock => mock.GetVariables()).Return(new[] { object1, object2 });
                _newTransactionMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 })));
            }
            Assert.That(_strategy.Scope, Is.SameAs(ScopeMock));
            MockRepository.ReplayAll();

            _strategy.Reset();

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.SameAs(newScopeMock));
        }
예제 #3
0
        public void Test_ReleaseThrows()
        {
            var strategy       = CreateScopedTransactionStrategy(false, NullTransactionStrategy.Null);
            var innerException = new Exception("Release Exception");

            InvokeOnExecutionPlay(strategy);
            ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub));
            ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]);
            ScopeMock.Expect(mock => mock.Leave());
            TransactionMock.Expect(mock => mock.Release()).Throw(innerException);

            MockRepository.ReplayAll();

            try
            {
                strategy.OnExecutionStop(Context, ExecutionListenerStub);
                Assert.Fail("Expected Exception");
            }
            catch (WxeFatalExecutionException actualException)
            {
                Assert.That(actualException.InnerException, Is.SameAs(innerException));
            }

            MockRepository.VerifyAll();
            Assert.That(strategy.Scope, Is.Null);
        }
        public void Test_ChildStrategyThrows()
        {
            var innerException = new ApplicationException("InnerListener Exception");

            InvokeOnExecutionPlay(_strategy);
            using (MockRepository.Ordered())
            {
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionPause(Context, ExecutionListenerStub)).Throw(innerException);
                ScopeMock.Expect(mock => mock.Leave());
            }

            MockRepository.ReplayAll();

            try
            {
                _strategy.OnExecutionPause(Context, ExecutionListenerStub);
                Assert.Fail("Expected Exception");
            }
            catch (ApplicationException actualException)
            {
                Assert.That(actualException, Is.SameAs(innerException));
            }

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.Null);
        }
예제 #5
0
        public void Test_WithScope_And_ResetThrows()
        {
            InvokeOnExecutionPlay(_strategy);
            var exception = new ApplicationException("Reset Exception");

            TransactionFactoryMock.BackToRecord();
            TransactionMock.BackToRecord();
            using (MockRepository.Ordered())
            {
                ScopeMock.Expect(mock => mock.Leave());
                TransactionMock.Expect(mock => mock.Release());
                TransactionFactoryMock.Expect(mock => mock.Create()).Throw(exception);
            }
            Assert.That(_strategy.Scope, Is.SameAs(ScopeMock));
            MockRepository.ReplayAll();

            try
            {
                _strategy.Reset();
                Assert.Fail("Expected Exception");
            }
            catch (ApplicationException actualException)
            {
                Assert.That(actualException, Is.SameAs(exception));
            }
            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.SameAs(ScopeMock));
            Assert.That(_strategy.Transaction, Is.SameAs(TransactionMock), "Transaction just released is retained.");
        }
예제 #6
0
        public void Test_ChildStrategyThrows_And_ReleaseThrows()
        {
            var innerException = new Exception("InnerListener Exception");
            var outerException = new Exception("Release Exception");

            InvokeOnExecutionPlay(_strategy);
            using (MockRepository.Ordered())
            {
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionFail(Context, ExecutionListenerStub, _failException)).Throw(innerException);
                ScopeMock.Expect(mock => mock.Leave());
                TransactionMock.Expect(mock => mock.Release()).Throw(outerException);
            }

            MockRepository.ReplayAll();

            try
            {
                _strategy.OnExecutionFail(Context, ExecutionListenerStub, _failException);
                Assert.Fail("Expected Exception");
            }
            catch (WxeFatalExecutionException actualException)
            {
                Assert.That(actualException.InnerException, Is.SameAs(innerException));
                Assert.That(actualException.OuterException, Is.SameAs(outerException));
            }

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.Null);
        }
        public void Test()
        {
            InvokeOnExecutionPlay(_strategy);

            using (MockRepository.Ordered())
            {
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionPause(Context, ExecutionListenerStub));
                ScopeMock.Expect(mock => mock.Leave());
            }

            MockRepository.ReplayAll();

            _strategy.OnExecutionPause(Context, ExecutionListenerStub);

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.Null);
        }
예제 #8
0
        public void Test_WithReleaseTransactionOverride()
        {
            InvokeOnExecutionPlay(_strategy);
            using (MockRepository.Ordered())
            {
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionFail(Context, ExecutionListenerStub, _failException));
                ScopeMock.Expect(mock => mock.Leave());
                _strategy.Expect(mock => PrivateInvoke.InvokeNonPublicMethod(mock, "ReleaseTransaction"));
            }

            MockRepository.ReplayAll();

            _strategy.OnExecutionFail(Context, ExecutionListenerStub, _failException);

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.Null);
        }
예제 #9
0
        public void Test_WithoutAutoCommit()
        {
            var strategy = CreateScopedTransactionStrategy(false, NullTransactionStrategy.Null);

            InvokeOnExecutionPlay(strategy);
            using (MockRepository.Ordered())
            {
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub));
                ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]);
                ScopeMock.Expect(mock => mock.Leave());
                TransactionMock.Expect(mock => mock.Release());
            }

            MockRepository.ReplayAll();

            strategy.OnExecutionStop(Context, ExecutionListenerStub);

            MockRepository.VerifyAll();
            Assert.That(strategy.Scope, Is.Null);
        }
예제 #10
0
        public void Test_WithScope_And_LeaveThrows()
        {
            InvokeOnExecutionPlay(_strategy);
            var exception = new ApplicationException("Leave Exception");

            using (MockRepository.Ordered())
            {
                ScopeMock.Expect(mock => mock.Leave()).Throw(exception);
            }
            Assert.That(_strategy.Scope, Is.SameAs(ScopeMock));
            MockRepository.ReplayAll();

            try
            {
                _strategy.Reset();
                Assert.Fail("Expected Exception");
            }
            catch (ApplicationException actualException)
            {
                Assert.That(actualException, Is.SameAs(exception));
            }
            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.SameAs(ScopeMock));
        }