public void OnException_Should_Set_Context_Result_As_UnAuthorized() { var context = new ExceptionContext(_actionContext, Enumerable.Empty <IFilterMetadata>().ToList()) { Exception = new UnauthorizedAccessException() }; var exceptionFilter = new ServiceExceptionFilter(_mockLoggerFactory.Object); exceptionFilter.OnException(context); JsonResult jsonResult = context.Result as JsonResult; ResultContent <string> result = jsonResult.Value as ResultContent <string>; string errorMessage = result.ErrorMessage; bool isError = !result.IsSuccess; context.Result.Should().BeOfType(typeof(JsonResult)); context.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.Unauthorized); errorMessage.Should().NotBeNullOrEmpty(); isError.Should().BeTrue(); }
public void OnException_Should_Set_Context_Result_As_InternalServerError() { string exceptionMessage = "Some Exception"; var context = new ExceptionContext(_actionContext, Enumerable.Empty <IFilterMetadata>().ToList()) { Exception = new Exception(exceptionMessage) }; var exceptionFilter = new ServiceExceptionFilter(_mockLoggerFactory.Object); exceptionFilter.OnException(context); JsonResult jsonResult = context.Result as JsonResult; ResultContent <string> result = jsonResult.Value as ResultContent <string>; string errorMessage = result.ErrorMessage; bool isError = !result.IsSuccess; context.Result.Should().BeOfType(typeof(JsonResult)); context.HttpContext.Response.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError); errorMessage.Should().Contain(exceptionMessage); isError.Should().BeTrue(); }