I am trying to test the following filter:
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace Hello
{
public class ValidationFilte
I just stumbled on the same problem and solved it in this way.
[Fact]
public void ValidateModelAttributes_SetsResultToBadRequest_IfModelIsInvalid()
{
var validationFilter = new ValidationFilter();
var modelState = new ModelStateDictionary();
modelState.AddModelError("name", "invalid");
var actionContext = new ActionContext(
Mock.Of(),
Mock.Of(),
Mock.Of(),
modelState
);
var actionExecutingContext = new ActionExecutingContext(
actionContext,
new List(),
new Dictionary(),
Mock.Of()
);
validationFilter.OnActionExecuting(actionExecutingContext);
Assert.IsType(actionExecutingContext.Result);
}