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

            Assert.True(filter.CanBeHandled(exception));
        }
        public void ByDefaultThereAreUnhandlableExceptionsAdded()
        {
            var substituteForErrorHandlingPolicy = Substitute.For <IExceptionHandlingPolicy>();
            var filter = new ExceptionHandlingFilter(substituteForErrorHandlingPolicy);

            Assert.True(filter.ExcludedExceptios.Contains(typeof(OutOfMemoryException)));
            Assert.True(filter.ExcludedExceptios.Contains(typeof(InsufficientExecutionStackException)));
        }
        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 FilterFiltersOut(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));
        }
        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);
        }
            public void OneTimeSetUp()
            {
                var httpControllerContext = new HttpControllerContext(
                    new HttpRequestContext(),
                    new HttpRequestMessage(),
                    new HttpControllerDescriptor(),
                    new TestController());

                var httpActionContext     = new HttpActionContext(httpControllerContext, new ReflectedHttpActionDescriptor());
                var actionExecutedContext = new HttpActionExecutedContext(httpActionContext, new BadRequestException());

                var exceptionHandlingFilter = new ExceptionHandlingFilter(true);

                exceptionHandlingFilter.ExecuteExceptionFilterAsync(actionExecutedContext, new CancellationToken())
                .Wait();

                response = actionExecutedContext.Response;
            }
 public void CanCreate()
 {
     var substituteForErrorHandlingPolicy = Substitute.For <IExceptionHandlingPolicy>();
     var filter = new ExceptionHandlingFilter(substituteForErrorHandlingPolicy);
 }