Beispiel #1
0
        public void OnException_WhenBusinessLogicException_Expects400BadRequest()
        {
            // Arrange
            var filter           = new QuizExceptionFilter();
            var ex               = new BusinessLogicException("CustomBusinessLogicException");
            var exceptionContext = this.MockExceptionContext(ex);

            // Act
            filter.OnException(exceptionContext);

            // Assert
            var result = Assert.IsType <BadRequestObjectResult>(exceptionContext.Result);

            Assert.Equal(400, result.StatusCode);
            var contract = Assert.IsType <ExceptionContract>(result.Value);

            Assert.Equal("CustomBusinessLogicException", contract.ErrorCode);
        }
Beispiel #2
0
        public void OnException_WhenNotABusinessLogicException_Expects500InternalServerError()
        {
            // Arrange
            var filter           = new QuizExceptionFilter();
            var ex               = new NullReferenceException("Custom exception");
            var exceptionContext = this.MockExceptionContext(ex);

            // Act
            filter.OnException(exceptionContext);

            // Assert
            var result = Assert.IsType <ObjectResult>(exceptionContext.Result);

            Assert.Equal(500, result.StatusCode);
            var contract = Assert.IsType <ExceptionContract>(result.Value);

            Assert.Equal("InternalServerError", contract.ErrorCode);
        }
Beispiel #3
0
        public void OnException_WhenEntityNotFoundException_Expects404NotFound()
        {
            // Arrange
            var filter           = new QuizExceptionFilter();
            var ex               = new EntityNotFoundException(typeof(Quiz), 1);
            var exceptionContext = this.MockExceptionContext(ex);

            // Act
            filter.OnException(exceptionContext);

            // Assert
            var result = Assert.IsType <NotFoundObjectResult>(exceptionContext.Result);

            Assert.Equal(404, result.StatusCode);
            var contract = Assert.IsType <ExceptionContract>(result.Value);

            Assert.Equal("EntityNotFound", contract.ErrorCode);
        }