Example #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);
        }
Example #2
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));
        }
Example #3
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));
        }