示例#1
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();
        }
示例#2
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();
            }
        }
示例#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);
        }
示例#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();
        }
        public void SetTransactionMode_AfterExecutionHasStarted_ThrowsInvalidOperationException()
        {
            TestFunction2 function = new TestFunction2();

            function.Add(
                new WxeDelegateStep(
                    () => Assert.That(
                        () => function.SetTransactionMode(WxeTransactionMode <TestTransactionFactory> .CreateRoot),
                        Throws.InvalidOperationException
                        .With.Message.EqualTo("The TransactionMode cannot be set after the TransactionStrategy has been initialized."))));

            WxeContextFactory contextFactory = new WxeContextFactory();
            var context = contextFactory.CreateContext(function);

            function.Execute(context);
        }
        public void SetTransactionMode()
        {
            TestFunction2        function          = new TestFunction2();
            ITransactionStrategy actualTransaction = null;

            function.Add(new WxeDelegateStep(() => actualTransaction = function.Transaction));
            function.SetTransactionMode(WxeTransactionMode <TestTransactionFactory> .CreateRoot);

            WxeContextFactory contextFactory = new WxeContextFactory();
            var context = contextFactory.CreateContext(function);

            Assert.That(function.Transaction, Is.InstanceOf <NullTransactionStrategy>());

            function.Execute(context);

            Assert.That(actualTransaction, Is.InstanceOf <RootTransactionStrategy>());
        }
示例#7
0
        public void Test_NoException()
        {
            TestFunction2 function = new TestFunction2();

            function.SetExecutionListener(_executionListenerMock);

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

            _mockRepository.ReplayAll();

            function.Execute(_context);

            _mockRepository.VerifyAll();
        }
示例#8
0
        public void Test_WithTransactionStrategy()
        {
            ITransactionMode        transactionModeMock     = _mockRepository.StrictMock <ITransactionMode>();
            TestFunction2           function                = new TestFunction2(transactionModeMock);
            TransactionStrategyBase transactionStrategyMock = MockRepository.GenerateMock <TransactionStrategyBase>();

            transactionModeMock.Expect(mock => mock.CreateTransactionStrategy(function, _context)).Return(transactionStrategyMock);
            transactionStrategyMock.Expect(mock => mock.CreateExecutionListener(Arg <IWxeFunctionExecutionListener> .Is.NotNull))
            .Return(_executionListenerMock);

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

            _mockRepository.ReplayAll();

            function.Execute(_context);

            _mockRepository.VerifyAll();
            Assert.That(function.ExecutionListener, Is.SameAs(_executionListenerMock));
        }
示例#9
0
        public void Test_UseNullListener()
        {
            TestFunction2 function = new TestFunction2();

            function.Execute(_context);
        }