public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (ValidateUser(model.UserName, model.Password)) { SetAuthCookie(model.UserName, model.RememberMe); if (LocalUrl(returnUrl)) { return Redirect(returnUrl); } return RedirectToAction("", "Elmah"); } ModelState.AddModelError("", "The user name or password provided is incorrect."); } return View(model); }
public void LogOn_Post_Test() { // Arrange TestableAccountController controller = new TestableAccountController(); controller.UserValid = true; LogOnModel model = new LogOnModel(); model.UserName = "******"; model.Password = "******"; // Act RedirectToRouteResult result = controller.LogOn(model, "") as RedirectToRouteResult; // Assert Assert.True(controller.ModelState.IsValid); Assert.True(controller.ValidateUserCalled); Assert.True(controller.SetAuthCookieCalled); Assert.True(result.RouteValues.Any(x => x.Key == "action" && (string)x.Value == "")); Assert.True(result.RouteValues.Any(x => x.Key == "controller" && (string)x.Value == "Elmah")); }
public void LogOn_Post_With_Return_Url_Test() { // Arrange TestableAccountController controller = new TestableAccountController(); controller.Url = GetUrlHelperForIsLocalUrl(); controller.UserValid = true; LogOnModel model = new LogOnModel(); model.UserName = "******"; model.Password = "******"; // Act RedirectResult result = controller.LogOn(model, "/elmah") as RedirectResult; // Assert Assert.True(controller.ModelState.IsValid); Assert.True(controller.ValidateUserCalled); Assert.True(controller.SetAuthCookieCalled); Assert.Equal("/elmah", result.Url); }