private void ShouldSetExceptionHandledIfATypeOfDomainException(Exception exception, bool expected)
            {
                var exceptionContext =
                    new ExceptionContext(
                        new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                        new List <IFilterMetadata>())
                {
                    Exception = exception
                };
                var filter = new DomainExceptionFilter();

                filter.OnException(exceptionContext);

                exceptionContext.ExceptionHandled.Should().Be(expected);
            }
            private void ShouldNotSetResultIfNotATypeOfDomainException()
            {
                var exceptionContext =
                    new ExceptionContext(
                        new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                        new List <IFilterMetadata>())
                {
                    Exception = new Exception()
                };
                var filter = new DomainExceptionFilter();

                filter.OnException(exceptionContext);

                exceptionContext.Result.Should().BeNull();
            }
            private void ShouldUseExceptionMapperForCustomExceptions()
            {
                var exceptionContext =
                    new ExceptionContext(
                        new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                        new List <IFilterMetadata>())
                {
                    Exception = new DomainException("Foo")
                };
                var filter = new DomainExceptionFilter((exception, response) => new OkResult());

                filter.OnException(exceptionContext);

                exceptionContext.Result.Should().BeEquivalentTo(new OkResult());
            }
            private void ShouldSetUnauthorizedResultIfUnauthorizedException()
            {
                var exceptionContext =
                    new ExceptionContext(
                        new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                        new List <IFilterMetadata>())
                {
                    Exception = new UnauthorizedException("Foo")
                };
                var filter = new DomainExceptionFilter();

                filter.OnException(exceptionContext);

                exceptionContext.Result.Should().BeEquivalentTo(new UnauthorizedResult());
            }
            private void ShouldSetBadRequestResultIfDomainException()
            {
                var exceptionContext =
                    new ExceptionContext(
                        new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                        new List <IFilterMetadata>())
                {
                    Exception = new DomainException("Foo")
                };
                var filter = new DomainExceptionFilter();

                filter.OnException(exceptionContext);

                exceptionContext.Result.Should().BeEquivalentTo(
                    new BadRequestObjectResult(new ErrorResponse(new DomainException("Foo"))));
            }
            private void ShouldSetNotFoundResultIfEntityNotFoundException()
            {
                EntityNotFoundException exception = EntityNotFoundException.Create <TestEntity, int>();
                var exceptionContext =
                    new ExceptionContext(
                        new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                        new List <IFilterMetadata>())
                {
                    Exception = exception
                };
                var filter = new DomainExceptionFilter();

                filter.OnException(exceptionContext);

                exceptionContext.Result.Should().BeEquivalentTo(new NotFoundObjectResult(new ErrorResponse(exception)));
            }