public void if_there_are_conditions_all_conditions_must_be_true_to_match() { var exception = new Exception(); var envelope = ObjectMother.Envelope(); var matchingCondition1 = MockRepository.GenerateMock <IExceptionMatch>(); var matchingCondition2 = MockRepository.GenerateMock <IExceptionMatch>(); var matchingCondition3 = MockRepository.GenerateMock <IExceptionMatch>(); var conditionThatDoesNotMatch = MockRepository.GenerateMock <IExceptionMatch>(); matchingCondition1.Stub(x => x.Matches(envelope, exception)).Return(true); matchingCondition2.Stub(x => x.Matches(envelope, exception)).Return(true); matchingCondition3.Stub(x => x.Matches(envelope, exception)).Return(true); conditionThatDoesNotMatch.Stub(x => x.Matches(envelope, exception)).Return(false); var handler = new ErrorHandler(); handler.AddCondition(matchingCondition1); handler.Matches(envelope, exception).ShouldBeTrue(); handler.AddCondition(matchingCondition2); handler.Matches(envelope, exception).ShouldBeTrue(); handler.AddCondition(matchingCondition3); handler.Matches(envelope, exception).ShouldBeTrue(); handler.AddCondition(conditionThatDoesNotMatch); handler.Matches(envelope, exception).ShouldBeFalse(); }
public void if_there_are_conditions_all_conditions_must_be_true_to_match() { var exception = new Exception(); var envelope = ObjectMother.Envelope(); var matchingCondition1 = Substitute.For <IExceptionMatch>(); var matchingCondition2 = Substitute.For <IExceptionMatch>(); var matchingCondition3 = Substitute.For <IExceptionMatch>(); var conditionThatDoesNotMatch = Substitute.For <IExceptionMatch>(); matchingCondition1.Matches(envelope, exception).Returns(true); matchingCondition2.Matches(envelope, exception).Returns(true); matchingCondition3.Matches(envelope, exception).Returns(true); var handler = new ErrorHandler(); handler.AddCondition(matchingCondition1); ShouldBeBooleanExtensions.ShouldBeTrue(handler.Matches(envelope, exception)); handler.AddCondition(matchingCondition2); ShouldBeBooleanExtensions.ShouldBeTrue(handler.Matches(envelope, exception)); handler.AddCondition(matchingCondition3); ShouldBeBooleanExtensions.ShouldBeTrue(handler.Matches(envelope, exception)); handler.AddCondition(conditionThatDoesNotMatch); ShouldBeBooleanExtensions.ShouldBeFalse(handler.Matches(envelope, exception)); }
public OnExceptionExpression(HandlerChain parent) { _parent = parent; _handler = new Lazy <ErrorHandler>(() => { var handler = new ErrorHandler(); handler.AddCondition(new ExceptionTypeMatch <T>()); _parent.ErrorHandlers.Add(handler); return(handler); }); }
public void if_nothing_matches_do_not_return_a_continuation() { var exception = new Exception(); var envelope = ObjectMother.Envelope(); var conditionThatDoesNotMatch = Substitute.For <IExceptionMatch>(); var handler = new ErrorHandler(); handler.AddCondition(conditionThatDoesNotMatch); ShouldBeNullExtensions.ShouldBeNull(handler.DetermineContinuation(envelope, exception)); }
public void if_nothing_matches_do_not_return_a_continuation() { var exception = new Exception(); var envelope = ObjectMother.Envelope(); var conditionThatDoesNotMatch = MockRepository.GenerateMock <IExceptionMatch>(); var handler = new ErrorHandler(); handler.AddCondition(conditionThatDoesNotMatch); handler.DetermineContinuation(envelope, exception) .ShouldBeNull(); }
public void return_the_continuation_if_the_handler_matches() { var exception = new Exception(); var envelope = ObjectMother.Envelope(); var matchingCondition1 = MockRepository.GenerateMock <IExceptionMatch>(); matchingCondition1.Stub(x => x.Matches(envelope, exception)).Return(true); var handler = new ErrorHandler(); handler.AddCondition(matchingCondition1); handler.AddContinuation(MockRepository.GenerateMock <IContinuation>()); handler.Matches(envelope, exception).ShouldBeTrue(); handler.DetermineContinuation(envelope, exception) .ShouldBeTheSameAs(handler.Continuation(null, null)); }
public void return_the_continuation_if_the_handler_matches() { var exception = new Exception(); var envelope = ObjectMother.Envelope(); var matchingCondition1 = Substitute.For <IExceptionMatch>(); matchingCondition1.Matches(envelope, exception).Returns(true); var handler = new ErrorHandler(); handler.AddCondition(matchingCondition1); handler.AddContinuation(Substitute.For <IContinuation>()); ShouldBeBooleanExtensions.ShouldBeTrue(handler.Matches(envelope, exception)); handler.DetermineContinuation(envelope, exception) .ShouldBeTheSameAs(handler.Continuation(null, null)); }