What Do You Think This Does?

3 commentsWritten on December 21st, 2009 by
Categories: quicknet

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?

  • http://davidnielsen.wordpress.com David Nielsen

    I have stared at it for 10 minutes and I can say with certainty.. it proves that your kung-fu is superior to mine.

  • ibrahim

    My guess is that it runs specs only after a specific exception occurs and checks the details (type, stack trace, etc) of that exception are correct.

  • http://davybrion.com Davy Brion

    @Ibrahim

    indeed it does