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 SetExecutionListener() { TestFunction2 function = new TestFunction2(); function.SetExecutionListener(_executionListenerMock); Assert.That(function.ExecutionListener, Is.SameAs(_executionListenerMock)); }
public void SetExecutionListener_AfterExecutionHasStarted_ThrowsInvalidOperationException() { TestFunction2 function = new TestFunction2(); function.Add( new WxeDelegateStep( () => Assert.That( () => function.SetExecutionListener(_executionListenerMock), Throws.InvalidOperationException .With.Message.EqualTo("The ExecutionListener cannot be set after the TransactionStrategy has been initialized.")))); WxeContextFactory contextFactory = new WxeContextFactory(); var context = contextFactory.CreateContext(function); function.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 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(); }
public void SetExecutionListenerNull() { TestFunction2 function = new TestFunction2(); Assert.That(() => function.SetExecutionListener(null), Throws.TypeOf <ArgumentNullException>()); }