public void LogOn_Post_ReturnsRedirectOnSuccess_WithLocalReturnUrl() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { Email = "someEmail", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, "/someUrl"); // Assert Assert.That(result, Is.InstanceOf(typeof(RedirectResult))); RedirectResult redirectResult = (RedirectResult)result; Assert.AreEqual("/someUrl", redirectResult.Url); //Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); }
public void LogOn_Post_ReturnsViewIfValidateUserFails() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { Email = "someEmail", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, null); // Assert Assert.That(result, Is.InstanceOf(typeof(ViewResult))); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("The user name or password provided is incorrect.", controller.ModelState[""].Errors[0].ErrorMessage); }
public void LogOn_Post_ReturnsRedirectToHomeOnSuccess_WithExternalReturnUrl() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { Email = "someEmail", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, "http://malicious.example.net"); // Assert Assert.That(result, Is.InstanceOf(typeof(RedirectToRouteResult))); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); Assert.AreEqual("Index", redirectResult.RouteValues["action"]); //Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); }
public void LogOn_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { Email = "someEmail", Password = "******", RememberMe = false }; controller.ModelState.AddModelError("", "Dummy error message."); // Act ActionResult result = controller.LogOn(model, null); // Assert Assert.That(result, Is.InstanceOf(typeof(ViewResult))); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (_membershipService.ValidateUser(model.Email, model.Password)) { _formsService.SignIn(model.Email, model.RememberMe); return !String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl) ? (ActionResult) Redirect(returnUrl) : RedirectToAction("Index", "Home"); } ModelState.AddModelError("", "The user name or password provided is incorrect."); } // If we got this far, something failed, redisplay form return View(model); }