views:

32

answers:

1

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.

A: 

This suggests the login failed. You can confirm this by debugging the test and tracing through controller.ChangePassword(model);. Testing any action involving authentication requires mocking or replacing the membership provider.

Craig Stuntz