예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }