I've been trying to find some straightforward information on this, but I haven't been able to - either what I've found has been to vague for me to understand what's going on, or too specific for the wrong thing, for example a tutorial I found for unit testing an AuthorizeAttribute. (A third alternative is of course that I'm too dumb to realize that I'm reading the information I'm looking for... in which case I still need help, because I'm dumb :P)
I'd like to be able to test two things:
- That a given ActionFilter is applied to an action (to make sure that the action meets requirements)
- That a given ActionFilter does what it's supposed to do.
And I'm clueless. Could anyone push me in the right direction as to what I actually need to test? What should my Arrange, Act and Assert sections of the tests contain?
A little detail, if I'm not clear enough:
I have a CustomValidationFilter
that is supposed to check if two submitted form values are the same, and add a ModelStateError
if not. I want to verify that the error is added with the correct error message if the values are not the same, and that the error is not added if the values are equal (and non-null).
I also have a Write
action on a GuestbookController
. I want to verify that the filter is applied to this action.