public void LoginOfInvalidUserShouldReturnViewWithUserData()
        {
            LoginUserViewModel user = new LoginUserViewModel { LoginName = "user", Password = "", RememberMe = true };

            AccountController controller = new AccountController(usersRepositoryMock.Object, webSecurityMock.Object);
            ActionResult actionResult = controller.Login(user);

            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));

            ViewResult viewResult = (ViewResult)actionResult;

            Assert.AreEqual(viewResult.Model, user);
        }
        public void LoginOfRegisteredUserShouldRedirectToHomeIndex()
        {
            webSecurityMock.Setup(t => t.Login("user", "pass", true)).Returns(true);
            LoginUserViewModel user = new LoginUserViewModel { LoginName = "user", Password = "******", RememberMe = true };

            AccountController controller = new AccountController(usersRepositoryMock.Object, webSecurityMock.Object);
            ActionResult actionResult = controller.Login(user);

            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirect = (RedirectToRouteResult)actionResult;

            Assert.AreEqual(redirect.RouteValues["action"], "index");
            Assert.AreEqual(redirect.RouteValues["controller"], "home");
        }
        public ActionResult Login(LoginUserViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return View(user);
            }

            if (WebSecurity.Login(user.LoginName, user.Password, persistCookie: user.RememberMe))
            {
                return RedirectToAction("index", "home");
            }

            ModelState.AddModelError(string.Empty, Strings.NoUserOrWrongPassword);

            return View(user);
        }