As suggested by (among others) Kazi Manzur Rashid in this blog post, I am using ActionFilterAttributes to transfer model state from one request to another when redirecting.
However, I find myself unable to write a unit test that test the behavior of these attributes. As an example, this what I want the test for the ImportModelStateAttribute to do:
- Setup the
filterContextso thatTempData[myKey]contains some fake "exported"ModelState(that is, aModelStateDictionaryI create myself, and add one error to) - Make
ModelStatecontain one model error. - Call
OnActionExecuting. - Verify the two dictionaries are merged, and
ModelStatenow contains both errors.
I'm at a loss already on the first step.
EDIT:
Yes, I've tried mocking ActionFilterAttribute with Moq, but I get errors stating
Invalid setup on non-overridable member
for both TempData and ModelState.