public void ChangePassword_Post_ReturnsRedirectOnSuccess()
        {
            // Arrange
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.ChangePassword(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(JavaScriptResult));
            JavaScriptResult JsResult = (JavaScriptResult)result;
            Assert.AreEqual("$('#success').fadeIn('slow');", JsResult.Script);
        }
        public void ChangePassword_Post_ReturnsViewIfChangePasswordFails()
        {
            // Arrange
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.ChangePassword(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(JavaScriptResult));
            JavaScriptResult viewResult = (JavaScriptResult)result;

            Assert.AreEqual("$('#fail').fadeIn('slow');",viewResult.Script);
               // Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
        public virtual ActionResult ChangePassword(ChangePasswordModel model)
        {
            var js = "$('.info_div').hide();$('#success').fadeIn('slow');";
            if (ModelState.IsValid)
            {
                if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                {

                    return JavaScript(js);
                }
                else
                {
                    ModelState.AddModelError("", "当前密码不正确或新密码强度不符合要求.");
                    js = "$('.info_div').hide();$('#fail').fadeIn('slow');";
                    return JavaScript(js);
                }
            }
            // If we got this far, something failed, redisplay form
            //ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            //return View(model);

            js = " $('.info_div').hide();$('#warning').fadeIn('slow');";
            return JavaScript(js);
        }
        public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // Arrange
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "Dummy error message.");

            // Act
            ActionResult result = controller.ChangePassword(model);

            // Assert
            Assert.IsInstanceOfType(result, typeof(JavaScriptResult));
            JavaScriptResult viewResult = (JavaScriptResult)result;
            Assert.AreEqual("$('#warning').fadeIn('slow');", viewResult.Script);
              // Assert.AreEqual(model, viewResult.ViewData.Model);
               // Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }