public void OnActionExecuting_ModelIsValid_ReturnDefaultRequest() { var filter = new ValidateModelFilterAttribute { TestRequestMessage = new HttpRequestMessage() }; var httpActionContext = new HttpActionContext(); filter.OnActionExecuting(httpActionContext); httpActionContext.Response.ShouldBe(null); }
public void OnActionExecuting_ModelIsInvalid_ReturnBadRequest() { var filter = new ValidateModelFilterAttribute { TestRequestMessage = new HttpRequestMessage() }; var httpActionContext = new HttpActionContext(); httpActionContext.ModelState.AddModelError("Error", "Fail"); filter.OnActionExecuting(httpActionContext); httpActionContext.Response.StatusCode.ShouldBe(HttpStatusCode.BadRequest); }
public virtual void SetUp() { Logger = new Mock <ILogger <ValidateModelFilterAttribute> >(); CorrelationCtx = new Mock <ICorrelationContextAccessor>(); ModelState = new ModelStateDictionary(); ActionContext = new ActionContext( Mock.Of <HttpContext>(), Mock.Of <RouteData>(), Mock.Of <ActionDescriptor>(), ModelState ); ExecutingContext = new ActionExecutingContext( ActionContext, new List <IFilterMetadata>(), new Dictionary <string, object>(), Mock.Of <Controller>() ); Subject = new ValidateModelFilterAttribute(Logger.Object, CorrelationCtx.Object); }