예제 #1
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);
        }
예제 #2
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);
        }
        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);
        }
예제 #4
0
        public void Test_EnsureCompatibility_ThrowsBecauseOfIncompatibleOutParameters()
        {
            var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock);
            var invalidOperationException = new InvalidOperationException("Completely bad objects!");

            InvokeOnExecutionPlay(strategy);
            ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub));

            ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]);
            OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .Is.Anything)).Throw(invalidOperationException);

            MockRepository.ReplayAll();

            Assert.That(
                () => strategy.OnExecutionStop(Context, ExecutionListenerStub),
                Throws
                .TypeOf <WxeException> ()
                .With.Message.EqualTo(
                    "One or more of the output parameters returned from the WxeFunction are incompatible with the function's parent transaction. "
                    + "Completely bad objects!")
                .And.InnerException.SameAs(invalidOperationException));

            MockRepository.VerifyAll();
            Assert.That(strategy.Scope, Is.SameAs(ScopeMock));
        }
예제 #5
0
        public void Test_ChildStrategyThrowsFatalException()
        {
            var innerException = new WxeFatalExecutionException(new Exception("InnerListener Exception"), null);

            using (MockRepository.Ordered())
            {
                TransactionMock.Expect(mock => mock.EnterScope()).Return(ScopeMock);
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionPlay(Context, ExecutionListenerStub)).Throw(innerException);
            }

            MockRepository.ReplayAll();

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

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.Not.Null);
        }
예제 #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);
        }
예제 #7
0
        public void Test()
        {
            using (MockRepository.Ordered())
            {
                TransactionMock.Expect(mock => mock.EnterScope()).Return(ScopeMock);
                ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionPlay(Context, ExecutionListenerStub));
            }

            MockRepository.ReplayAll();

            _strategy.OnExecutionPlay(Context, ExecutionListenerStub);

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.SameAs(ScopeMock));
        }
        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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
        public void Test_EnsureCompatibilityThrowsUnexpected_GetsBubbledOut()
        {
            var strategy       = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock);
            var innerException = new ApplicationException("GetOutParameters Exception");

            InvokeOnExecutionPlay(strategy);
            ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub));

            ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]);
            OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .Is.Anything)).Throw(innerException);

            MockRepository.ReplayAll();

            Assert.That(
                () => strategy.OnExecutionStop(Context, ExecutionListenerStub),
                Throws.Exception.SameAs(innerException));


            MockRepository.VerifyAll();
            Assert.That(strategy.Scope, Is.SameAs(ScopeMock));
        }
        public void Test_ChildStrategyThrowsFatalException()
        {
            var innerException = new WxeFatalExecutionException(new Exception("ChildStrategy Exception"), null);

            InvokeOnExecutionPlay(_strategy);
            ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionPause(Context, ExecutionListenerStub)).Throw(innerException);

            MockRepository.ReplayAll();

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

            MockRepository.VerifyAll();
            Assert.That(_strategy.Scope, Is.Not.Null);
        }
예제 #13
0
        public void Test_ChildStrategyThrows()
        {
            var strategy       = CreateScopedTransactionStrategy(true, NullTransactionStrategy.Null);
            var innerException = new ApplicationException("InnerListener Exception");

            InvokeOnExecutionPlay(strategy);
            ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)).Throw(innerException);

            MockRepository.ReplayAll();

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

            MockRepository.VerifyAll();
            Assert.That(strategy.Scope, Is.SameAs(ScopeMock));
        }