public void ChangePassword_Post_ReturnsRedirectOnSuccess() { // Arrange var model = new AccountChangePasswordModel { Email = "*****@*****.**", OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; // Act ActionResult result = _accountController.ChangePassword(model); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); var redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]); }
public ActionResult ChangePassword(AccountChangePasswordModel model) { if (string.IsNullOrEmpty(model.OldPassword)) { if (!_currentUser.IsAdmin) ModelState.AddModelError("OldPassword", "The Current password field is required."); else model.OldPassword = "******"; } if (ModelState.IsValid) { if (_membershipService.ChangePassword(model.Email, model.OldPassword, model.NewPassword)) return RedirectTo<AccountController>(c => c.ChangePasswordSuccess()); ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } // If we got this far, something failed, redisplay form return View(model); }
public void ChangePassword_Post_ReturnsViewIfChangePasswordFails() { // Arrange var model = new AccountChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; // Act ActionResult result = _accountController.ChangePassword(model); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); var viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("The current password is incorrect or the new password is invalid.", _accountController.ModelState[""].Errors[0].ErrorMessage); }
public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange var model = new AccountChangePasswordModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; _accountController.ModelState.AddModelError("", "Dummy error message."); // Act ActionResult result = _accountController.ChangePassword(model); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); var viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); }