A well-known benefit of MVC is its suitablility for Test Driven Development (TDD) because you can directly call your controller actions from your test methods.
How can you test the combination of a controller action with a ActionFilter
attribute (using OnActionExecuted
to modify the ActionResult
returned by the Action)? If I just call the Action, it returns the ActionResult
from the action, but the filter attribute is never invoked. I think maybe you can get it by Controller.ActionInvoker.InvokeAction(controllerContext, "ActionName")
, but you have to accurately mock so much of the controllerContext to make it work that it's a real pain.
Has anyone successfully done this?