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 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 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"]); }