Example #1
0
        public void Test_ThreadAbort_WithFatalException()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep step1 = MockRepository.GenerateMock <WxeStep> ();

            step1.Expect(mock => mock.Execute(_context)).WhenCalled(invocation => Thread.CurrentThread.Abort());
            function.Add(step1);

            var fatalExecutionException = new WxeFatalExecutionException(new Exception("Pause exception"), null);

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionPause(_context)).Throw(fatalExecutionException);
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (WxeFatalExecutionException actualException)
            {
                Assert.That(actualException, Is.SameAs(fatalExecutionException));
                Thread.ResetAbort();
            }
        }
Example #2
0
        public void Test_FailAfterExceptionAndFailInListener()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep   step1         = MockRepository.GenerateMock <WxeStep> ();
            Exception stepException = new Exception("StepException");

            step1.Expect(mock => mock.Execute(_context)).Throw(stepException);
            function.Add(step1);

            Exception listenerException = new Exception("ListenerException");

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionFail(_context, stepException)).Throw(listenerException);
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (WxeFatalExecutionException actualException)
            {
                Assert.That(actualException.InnerException, Is.SameAs(stepException));
                Assert.That(actualException.OuterException, Is.SameAs(listenerException));
            }

            _mockRepository.VerifyAll();
        }
Example #3
0
        public void CreateTransactionStrategy_WithParentTransaction()
        {
            ITransactionMode transactionMode = new CreateChildIfParentTransactionMode(true, new TestTransactionFactory());

            WxeFunction parentFunction = new TestFunction2(new CreateRootTransactionMode(true, new TestTransactionFactory()));
            WxeFunction childFunction  = new TestFunction2(transactionMode);

            parentFunction.Add(childFunction);

            WxeStep stepMock = MockRepository.GenerateMock <WxeStep>();

            childFunction.Add(stepMock);

            WxeContextFactory wxeContextFactory = new WxeContextFactory();
            WxeContext        context           = wxeContextFactory.CreateContext(new TestFunction());

            stepMock.Expect(mock => mock.Execute(context)).WhenCalled(
                invocation =>
            {
                TransactionStrategyBase strategy = ((TestFunction2)childFunction).TransactionStrategy;
                Assert.That(strategy, Is.InstanceOf(typeof(ChildTransactionStrategy)));
                Assert.That(((ChildTransactionStrategy)strategy).AutoCommit, Is.True);
                Assert.That(strategy.OuterTransactionStrategy, Is.SameAs(((TestFunction2)parentFunction).TransactionStrategy));
            });

            parentFunction.Execute(context);
        }
Example #4
0
        public void Test_ReEntryAfterThreadAbort()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

            WxeStep step1 = MockRepository.GenerateMock <WxeStep> ();

            step1.Expect(mock => mock.Execute(_context)).WhenCalled(invocation => Thread.CurrentThread.Abort()).Repeat.Once();
            function.Add(step1);

            WxeStep step2 = MockRepository.GenerateMock <WxeStep>();

            step2.Expect(mock => mock.Execute(_context));
            function.Add(step2);

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionPause(_context));
            }
            _mockRepository.ReplayAll();

            try
            {
                function.Execute(_context);
                Assert.Fail();
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }

            _mockRepository.VerifyAll();
            _mockRepository.BackToRecordAll();

            using (_mockRepository.Ordered())
            {
                _executionListenerMock.Expect(mock => mock.OnExecutionPlay(_context));
                _executionListenerMock.Expect(mock => mock.OnExecutionStop(_context));
            }
            _mockRepository.ReplayAll();

            function.Execute(_context);

            _mockRepository.VerifyAll();
        }