I’m only going to show a part of a QuickNet Acid Test, and i’m intentionally leaving a lot of things out:
private void EnsureExceptionInfoIsCorrect(Predicate<Exception> exceptionPredicate, ExceptionType exceptionTypeEnum, Type exceptionType, Response[] responses)
{
int index = exceptionsThrownFromRequestHandlers.FindIndex(exceptionPredicate);
Ensure.Equal(exceptionTypeEnum, responses[index].ExceptionType);
Ensure.Equal(exceptionsThrownFromRequestHandlers[index].Message, responses[index].Exception.Message);
Ensure.Equal(exceptionsThrownFromRequestHandlers[index].StackTrace, responses[index].Exception.StackTrace);
Ensure.Equal(exceptionType.FullName, responses[index].Exception.Type);
}
[SpecFor(typeof(ProcessRequestsTransition))]
public Spec ProcessRequestsWithBusinessException(ProcessInput input, Response[] output)
{
Predicate<Exception> predicate = exception => exception != null && exception.GetType() == typeof(BusinessException);
return new Spec(() => EnsureExceptionInfoIsCorrect(predicate, ExceptionType.Business, typeof(BusinessException), output))
.IfAfter(() => exceptionsThrownFromRequestHandlers.Exists(predicate));
}
[SpecFor(typeof(ProcessRequestsTransition))]
public Spec ProcessRequestsWithSecurityException(ProcessInput input, Response[] output)
{
Predicate<Exception> predicate = exception => exception != null && exception.GetType() == typeof(SecurityException);
return new Spec(() => EnsureExceptionInfoIsCorrect(predicate, ExceptionType.Security, typeof(SecurityException), output))
.IfAfter(() => exceptionsThrownFromRequestHandlers.Exists(predicate));
}
[SpecFor(typeof(ProcessRequestsTransition))]
public Spec ProcessRequestsWithUnknownException(ProcessInput input, Response[] output)
{
Predicate<Exception> predicate = exception => exception != null && exception.GetType() == typeof(UnknownException);
return new Spec(() => EnsureExceptionInfoIsCorrect(predicate, ExceptionType.Unknown, typeof(UnknownException), output))
.IfAfter(() => exceptionsThrownFromRequestHandlers.Exists(predicate));
}
[SpecFor(typeof(ProcessRequestsTransition))]
public Spec ProcessRequestsWithAnotherUnknownException(ProcessInput input, Response[] output)
{
Predicate<Exception> predicate = exception => exception != null && exception.GetType() == typeof(AnotherUnknownException);
return new Spec(() => EnsureExceptionInfoIsCorrect(predicate, ExceptionType.Unknown, typeof(AnotherUnknownException), output))
.IfAfter(() => exceptionsThrownFromRequestHandlers.Exists(predicate));
}
Now, what do you think this does?