public void FilterPassesExceptionHandlingToUnderlying(Type exceptionToExcludeType)
        {
            var substituteForErrorHandlingPolicy = Substitute.For <IExceptionHandlingPolicy>();
            var filter    = new ExceptionHandlingFilter(substituteForErrorHandlingPolicy);
            var exception = (Exception)Activator.CreateInstance(exceptionToExcludeType);

            filter.HandleException(exception);

            substituteForErrorHandlingPolicy.Received(1).HandleException(Arg.Is(exception));
        }
        public void FilterDoesNotPassExceptionHandlingToUnderlyingIfCannotBeHandled(Type exceptionToExcludeType)
        {
            var substituteForErrorHandlingPolicy = Substitute.For <IExceptionHandlingPolicy>();
            var filter = new ExceptionHandlingFilter(substituteForErrorHandlingPolicy);

            filter.ExcludedExceptios.Add(exceptionToExcludeType);
            var exception = (Exception)Activator.CreateInstance(exceptionToExcludeType);


            Assert.Throws <ExceptionCannotBeHandledException>(() => filter.HandleException(exception));
            substituteForErrorHandlingPolicy.DidNotReceiveWithAnyArgs().HandleException(Arg.Any <Exception>());
        }
        public void FilterThrowsExceptionWrappedIfItCannotBeHandled(Type exceptionToExcludeType)
        {
            var substituteForErrorHandlingPolicy = Substitute.For <IExceptionHandlingPolicy>();
            var filter = new ExceptionHandlingFilter(substituteForErrorHandlingPolicy);

            filter.ExcludedExceptios.Add(exceptionToExcludeType);
            var exception = (Exception)Activator.CreateInstance(exceptionToExcludeType);

            Assert.False(filter.CanBeHandled(exception));
            var rec = Assert.Throws <ExceptionCannotBeHandledException>(() => filter.HandleException(exception));

            Assert.True(rec.InnerException.GetType() == exceptionToExcludeType);
            Assert.Equal(rec.InnerException, exception);
        }