public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword)) { return RedirectToAction("ChangePasswordSuccess"); } else { ModelState.AddModelError("", "La contraseña actual es incorrecta o la nueva contraseña no es válida."); } } // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }
public void ChangePassword_Post_ReturnsRedirectOnSuccess() { // Disponer AccountController controller = GetAccountController(); ChangePasswordModel model = new ChangePasswordModel() { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; // Actuar ActionResult result = controller.ChangePassword(model); // Declarar Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]); }
public void ChangePassword_Post_ReturnsViewIfChangePasswordFails() { // Disponer AccountController controller = GetAccountController(); ChangePasswordModel model = new ChangePasswordModel() { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; // Actuar ActionResult result = controller.ChangePassword(model); // Declarar Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("La contraseña actual es incorrecta o la nueva contraseña no es válida.", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid() { // Disponer AccountController controller = GetAccountController(); ChangePasswordModel model = new ChangePasswordModel() { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; controller.ModelState.AddModelError("", "Mensaje de error ficticio."); // Actuar ActionResult result = controller.ChangePassword(model); // Declarar Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }