Changing User in MVC 2 MockHttpContext breaks Test?


Changing User in MVC 2 MockHttpContext breaks Test?



I changed the following line:

private readonly IPrincipal _user =         new GenericPrincipal(new GenericIdentity("someUser"), null /* roles */); 

to

 private readonly IPrincipal _user =         new GenericPrincipal(new GenericIdentity("realUser"), null /* roles */); 

and the following test broke, but I am not sure why and I am not sure how to trace it. I am new to TDD

    [TestMethod]     public void ChangePassword_Post_ReturnsRedirectOnSuccess()     {         // Arrange         AccountController controller = GetAccountController();         ChangePasswordModel model = new ChangePasswordModel()         {             OldPassword = "goodOldPassword",             NewPassword = "goodNewPassword",             ConfirmPassword = "goodNewPassword"         };          // Act         ActionResult result = controller.ChangePassword(model);          // Assert         Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));         RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;         Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]);     } 

An explanation of how this works and why changing someUser to realUser would break the above test would be very helpful.




Implementing a class-level validation attribute that writes to a property inside the class

1:



ASP.NET MVC2 CrAzY Characters in View Output - WTF
This suggests the login failed.


PDFsharp can't find image (image not found)
You can confirm this by debugging the test and tracing through controller.ChangePassword(model);.


MvcSitemapProvider is returning all in Https instead of Http
Testing any action involving authentication requires mocking or replacing the membership provider..
Development on ASP.NET MVC Storefront Project


Unit testing ASP.NET MVC Controller methods through concrete class or interface


64 out of 100 based on 29 user ratings 354 reviews