public void LogOn_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // 排列
            AccountController controller = GetAccountController();
            LogOnModel model = new LogOnModel()
            {
                UserName = "******",
                Password = "******",
                RememberMe = false
            };
            controller.ModelState.AddModelError("", "虚拟错误消息。");

            // 操作
            ActionResult result = controller.LogOn(model, null);

            // 断言
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
        }
        public void LogOn_Post_ReturnsViewIfValidateUserFails()
        {
            // 排列
            AccountController controller = GetAccountController();
            LogOnModel model = new LogOnModel()
            {
                UserName = "******",
                Password = "******",
                RememberMe = false
            };

            // 操作
            ActionResult result = controller.LogOn(model, null);

            // 断言
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("提供的用户名或密码不正确。", controller.ModelState[""].Errors[0].ErrorMessage);
        }
        public void LogOn_Post_ReturnsRedirectOnSuccess_WithReturnUrl()
        {
            // 排列
            AccountController controller = GetAccountController();
            LogOnModel model = new LogOnModel()
            {
                UserName = "******",
                Password = "******",
                RememberMe = false
            };

            // 操作
            ActionResult result = controller.LogOn(model, "/someUrl");

            // 断言
            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            RedirectResult redirectResult = (RedirectResult)result;
            Assert.AreEqual("/someUrl", redirectResult.Url);
            Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled);
        }