public static void NoException_DoesNothing() { var attribute = new ModuleExceptionFilterAttribute(); var actionContext = new HttpActionContext { Response = new HttpResponseMessage(HttpStatusCode.OK) }; var actionExecutedContext = new HttpActionExecutedContext(actionContext, null); attribute.OnException(actionExecutedContext); Assert.Equal(HttpStatusCode.OK, actionExecutedContext.Response.StatusCode); }
public static void SystemException_DoesNotExposeDetails() { var attribute = new ModuleExceptionFilterAttribute(); var actionContext = new HttpActionContext { Response = new HttpResponseMessage(HttpStatusCode.OK), }; var actionExecutedContext = new HttpActionExecutedContext(actionContext, new Exception("Danger")); attribute.OnException(actionExecutedContext); Assert.Equal(HttpStatusCode.InternalServerError, actionExecutedContext.Response.StatusCode); Assert.NotEqual("Danger", actionExecutedContext.Response.Content.ReadAsStringAsync().Result); }
public static void ArgumentException_BadRequest( Exception exception, HttpStatusCode expectedStatusCode) { var attribute = new ModuleExceptionFilterAttribute(); var actionContext = new HttpActionContext { Response = new HttpResponseMessage(HttpStatusCode.OK), }; var actionExecutedContext = new HttpActionExecutedContext(actionContext, exception); actionExecutedContext.ActionContext.ControllerContext = new HttpControllerContext(); attribute.OnException(actionExecutedContext); Assert.Equal(expectedStatusCode, actionExecutedContext.Response.StatusCode); }