public void Login_Post_Action_Should_check_for_validation_errors() { var loginModel = new LoginModel { Username = "******", Password = "******" }; sut.ModelState.AddModelError("UserName", "UserName is required"); var actual = sut.Login(loginModel, "/"); Assert.IsInstanceOf<ViewResult>(actual); }
public void Should_redirect_to_Admin_area_if_credentials_are_correct() { var loginModel = new LoginModel { Username = "******", Password = "******" }; mockedAuthenticationService.Stub(s => s.LogOn(loginModel.Username, loginModel.Password)).Return(true); var actual = sut.Login(loginModel, "/"); Assert.IsInstanceOf<RedirectToRouteResult>(actual); Assert.AreEqual("Manage", ((RedirectToRouteResult)actual).RouteValues["action"]); }
public void Should_return_Login_page_if_credentials_are_incorrect() { var loginModel = new LoginModel { Username = "******", Password = "******" }; mockedAuthenticationService.Stub(s => s.LogOn(loginModel.Username, loginModel.Password)).Return(false); var actual = sut.Login(loginModel, "/"); var modelStateErrors = sut.ModelState[""].Errors; Assert.IsInstanceOf<ActionResult>(actual); Assert.IsTrue(modelStateErrors.Count > 0); Assert.AreEqual("The user name or password provided is incorrect.", modelStateErrors[0].ErrorMessage); }
public ActionResult Login(LoginModel loginModel, string returnUrl) { if (ModelState.IsValid && authenticationService.LogOn(loginModel.Username, loginModel.Password)) { return RedirectToAction("Manage"); } ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect."); return View(); }