public void ChangePasswordPostReturnsRedirectOnSuccess() { AccountController controller = GetAccountController(new MockMembershipService()); var model = new ChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; ActionResult result = controller.ChangePassword(model); Assert.IsInstanceOf<RedirectToRouteResult>(result); var redirectResult = (RedirectToRouteResult) result; Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]); }
public void ChangePasswordPostReturnsViewIfModelStateIsInvalid() { AccountController controller = GetAccountController(new MockMembershipService()); var model = new ChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; controller.ModelState.AddModelError("", "Dummy error message."); ActionResult result = controller.ChangePassword(model); Assert.IsInstanceOf<ViewResult>(result); var viewResult = (ViewResult) result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public void ChangePasswordPostReturnsViewWithCorrectMessageIfChangePasswordFails() { AccountController controller = GetAccountController(new MockMembershipService()); var model = new ChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; ActionResult result = controller.ChangePassword(model); Assert.IsInstanceOf<ViewResult>(result); var viewResult = (ViewResult) result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("The current password is incorrect or the new password is invalid.", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }