public void Login_Post_Return_InValidModel()
        {
            LoginViewModel model = new LoginViewModel() { UserName = "******", Password = "******" };

            _controller.ModelState.AddModelError("", "Invalid Model");

            var result = _controller.Login(model);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public void Login_Post_Return_InValidUser()
        {
            LoginViewModel model = new LoginViewModel() { UserName = "******", Password = "******" };

            var result = _controller.Login(model);
            var rresult = (ViewResult)result;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsInstanceOfType(rresult.Model, typeof(LoginViewModel));
        }
        public void Login_Post_Return_NotNull()
        {
            LoginViewModel model = new LoginViewModel() { UserName = "******", Password = "******" };

            IList<User> users = new List<User>();
            users.Add(new User() { Id = 1, userName = "******", password = "******", status = true });
            users.Add(new User() { Id = 2, userName = "******", password = "******", status = false });

            _mockAccount.Setup(a => a.getUsers()).Returns(users);

            var result = _controller.Login(model);
            var rresult = (RedirectToRouteResult)result;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual(rresult.RouteValues["action"], "Index");
            Assert.AreEqual(rresult.RouteValues["controller"], "Home");
        }
        public ActionResult Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
                return View();

            if (this._accountServices.getUsers().Any(a => a.userName == model.UserName && a.password == model.Password && a.status == true))
            {
                var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.UserName), }, DefaultAuthenticationTypes.ApplicationCookie);

                this._auth.SignIn(new AuthenticationProperties
                {
                    IsPersistent = model.RememberMe
                }, identity);

                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
            }
        }