コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }