I have a controller action that checks
this.User.Identity.IsAuthenticated
What do you suggest how to tackle unit test on such an action?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would suggest mocking the IsAuthenticated property. There are a number of other posts on SO about this, you could do a search for them.
Here is an example of mocking the request using Moq:
I would highly suggest looking into Scott Hanselman’s ubiquitous “MvcMockHelpers” code, which is what I use:
http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx