示例#1
0
            public void Multiple_null_arguments_should_trigger_filter()
            {
                var httpActionDescriptor = Stub <HttpActionDescriptor>();

                var controllerContext = new HttpControllerContext
                {
                    Request = new HttpRequestMessage()
                };

                var actionContext = new HttpActionContext(controllerContext, httpActionDescriptor);
                var actionFilter  = new CheckModelForNullAttribute();

                actionContext.ActionArguments.Add("requestParameter", null);
                actionContext.ActionArguments.Add("classParameter", null);

                actionFilter.OnActionExecuting(actionContext);
                var response = actionContext.Response;

                response.ShouldNotBeNull();
                response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

                var responseMessage = response.Content.ReadAsStringAsync()
                                      .Result;

                responseMessage.ShouldBe("{\"Message\":\"The request is invalid because it is missing requestParameter', 'classParameter \"}");
            }
示例#2
0
            public void Existing_arguments_should_not_trigger_filter()
            {
                var actionContext = new HttpActionContext();
                var actionFilter  = new CheckModelForNullAttribute();

                actionContext.ActionArguments.Add("request", "ParameterValue");
                actionContext.ActionArguments.Add("classParameter", new CheckModelForNullAttribute());

                actionFilter.OnActionExecuting(actionContext);
                actionContext.Response.ShouldBeNull();
            }
示例#3
0
            public void Existing_arguments_should_not_trigger_filter()
            {
                actioncontext                  = new ActionContext();
                actioncontext.HttpContext      = A.Fake <HttpContext>();
                actioncontext.RouteData        = A.Fake <RouteData>();
                actioncontext.ActionDescriptor = A.Fake <ActionDescriptor>();
                filtermetadata                 = A.Fake <IList <IFilterMetadata> >();
                actionarguments                = A.Fake <IDictionary <string, object> >();
                actionexecutingcontext         = new ActionExecutingContext(actioncontext, filtermetadata, actionarguments, this);
                var actionFilter = new CheckModelForNullAttribute();

                actionexecutingcontext.ActionDescriptor.Properties.Add("request", "ParameterValue");
                actionexecutingcontext.ActionDescriptor.Properties.Add("classParameter", new CheckModelForNullAttribute());

                actionFilter.OnActionExecuting(actionexecutingcontext);
                actionexecutingcontext.Result.ShouldBeNull();
            }
示例#4
0
            public void Multiple_null_arguments_should_trigger_filter()
            {
                var actionFilter = new CheckModelForNullAttribute();

                actioncontext                  = new ActionContext();
                actioncontext.HttpContext      = A.Fake <HttpContext>();
                actioncontext.RouteData        = A.Fake <RouteData>();
                actioncontext.ActionDescriptor = A.Fake <ActionDescriptor>();
                filtermetadata                 = A.Fake <IList <IFilterMetadata> >();
                actionarguments                = A.Fake <IDictionary <string, object> >();
                actionexecutingcontext         = new ActionExecutingContext(actioncontext, filtermetadata, actionarguments, this);
                actionexecutingcontext.ActionDescriptor.Properties.Add("request", null);
                actionexecutingcontext.ActionDescriptor.Properties.Add("classParameter", null);

                actionFilter.OnActionExecuting(actionexecutingcontext);
                BadRequestObjectResult response = (BadRequestObjectResult)actionexecutingcontext.Result;

                response.ShouldNotBeNull();

                var responseMessage = response.Value;

                responseMessage.ShouldBe("The request is invalid because it is missing request', 'classParameter ");
            }