예제 #1
0
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
        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"]);
        }