public void SignInShouldValidateAndAuthenticateUserWhenPostedTo() { mockMembershipService.Setup(ms => ms.ValidateUser("username", "password")).Returns(true); var userController = new UserController(mockAuthenticationService.Object, mockMembershipService.Object, mockUserRepository.Object); var model = new UserSignInViewModel { Password = "******", StaySignedIn = false, Username = "******" }; userController.SignIn(model, null); mockMembershipService.Verify(ms => ms.ValidateUser("username", "password"), Times.Once()); mockAuthenticationService.Verify(auth => auth.SignIn("username", false), Times.Once()); }
public void SignInShouldRedirectToReturnUrlWhenAuthenticationIsSuccessful() { mockMembershipService.Setup(ms => ms.ValidateUser(It.IsAny<string>(), It.IsAny<string>())).Returns(true); var userController = new UserController(mockAuthenticationService.Object, mockMembershipService.Object, mockUserRepository.Object); var model = new UserSignInViewModel { Password = "******", StaySignedIn = false, Username = "******" }; var result = userController.SignIn(model, "/test/page") as RedirectResult; Assert.IsNotNull(result); Assert.AreEqual("/test/page", result.Url); }
public void SignInShouldRedirectToNotesIndexWhenAuthenticationIsSuccessfulAndReturnUrlIsNotSpecified() { mockMembershipService.Setup(ms => ms.ValidateUser(It.IsAny<string>(), It.IsAny<string>())).Returns(true); var userController = new UserController(mockAuthenticationService.Object, mockMembershipService.Object, mockUserRepository.Object); var model = new UserSignInViewModel { Password = "******", StaySignedIn = false, Username = "******" }; var result = userController.SignIn(model, null) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual("index", result.RouteValues["action"]); Assert.AreEqual("notes", result.RouteValues["controller"]); }
public ActionResult SignIn(UserSignInViewModel model, string returnUrl) { if (membershipService.ValidateUser(model.Username, model.Password)) { authenticationService.SignIn(model.Username, model.StaySignedIn); if (string.IsNullOrEmpty(returnUrl) == false) { return Redirect(returnUrl); } return RedirectToAction("index", "notes"); } ModelState.AddModelError("", "The username or password provided is incorrect."); return View(model); }