Example #1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "現在のパスワードが正しくないか、新しいパスワードが無効です。");
                }
            }

            // ここで問題が発生した場合はフォームを再表示します
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }
Example #2
0
        public void ChangePassword_Post_ReturnsRedirectOnSuccess()
        {
            // 準備
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };

            // 実行
            ActionResult result = controller.ChangePassword(model);

            // アサート
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]);
        }
Example #3
0
        public void ChangePassword_Post_ReturnsViewIfChangePasswordFails()
        {
            // 準備
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };

            // 実行
            ActionResult result = controller.ChangePassword(model);

            // アサート
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("現在のパスワードが正しくないか、新しいパスワードが無効です。", controller.ModelState[""].Errors[0].ErrorMessage);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
Example #4
0
        public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // 準備
            AccountController controller = GetAccountController();
            ChangePasswordModel model = new ChangePasswordModel()
            {
                OldPassword = "******",
                NewPassword = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "ダミー エラー メッセージ。");

            // 実行
            ActionResult result = controller.ChangePassword(model);

            // アサート
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }