How can i write test case for action filters? I am using forms authentication.
I have base controller decorated with RequiresAuthentication action filter. When i execute the controller’s test case, i am not getting the loggedin user’s data from the cookies.
I am using Moq; does it provide a way to achieve my goal?
This blog post from Scott Hanselmann covers MvcMockHelpers including
FakeHttpContextfor different mocking frameworks among others also Moq:Another good resource for ASP.NET MVC test helpers is the MvcContrib project on CodePlex.
After you have a
FakeHttpContextyou can test your action filter: