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(); }
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(); } }
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); }
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>()); }