我更改了以下行:
private readonly IPrincipal _user =
new GenericPrincipal(new GenericIdentity("someUser"), null /* roles */);
到
private readonly IPrincipal _user =
new GenericPrincipal(new GenericIdentity("realUser"), null /* roles */);
并且以下测试破了,但我不确定为什么,我不确定如何追踪它。我是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"]);
}
解释这是如何工作的以及为什么将someUser更改为realUser会破坏上述测试会非常有帮助。
答案 0 :(得分:0)
这表明登录失败。您可以通过调试测试和跟踪controller.ChangePassword(model);
来确认这一点。测试涉及身份验证的任何操作都需要模拟或替换成员资格提供程序。