MVC - Unit Test Authentication Across Controllers
I have an ASP.NET MVC 3 application and am tes开发者_开发问答ting the controllers. My scenario is a common one - access to all pages requires authentication (save the Login page). I want to write tests to make sure that each controller action only allows access if the user is authenticated and authorized, but it seems strange to make this identical test for what could be hundreds of actions.
How is this usually handled?
Are you using the Authorize attribute which comes with MVC? If so, you could do a test, that through reflection inspect all actions on all controllers and verifies, that the Authorize attribute is present.
精彩评论