public void login_should_authentificate_user_when_user_is_valid()
        {
            //Arrange
            var user = _fixture.Create<MiamUser>();
            var loginViewModel = new LoginViewModel()
                                 {
                                    Email = user.Email,
                                    Password = user.Password
                                 };

            var valideUser = new MayBe<MiamUser>(user);
            _userAccountService.ValidateUser(loginViewModel.Email, loginViewModel.Password).Returns(valideUser);

            //Action
            _accountController.Login(loginViewModel);

            //Assert
            _httpContext.Received().AuthenticationSignIn(Arg.Any<ClaimsIdentity>());
        }
Ejemplo n.º 2
0
        public virtual ActionResult Login(LoginViewModel accountLoginViewModel)
        {
            if (!ModelState.IsValid)
            {
                return View("");
            }

            var user = _userAccountService.ValidateUser(accountLoginViewModel.Email, accountLoginViewModel.Password);

            if (!user.Any())
            {
                ModelState.AddModelError("loginError", UiText.Login.INCORRECT_LOGIN_OR_PASSWORD);
                return View("");
            }

            AuthentificateUser(user.First());

            return RedirectToAction(MVC.Home.Index());
        }
        public void login_should_redirect_to_home_index_when_user_is_valid()
        {
            //Arrange
            var user = _fixture.Create<MiamUser>();
            var loginViewModel = new LoginViewModel()
            {
                Email = user.Email,
                Password = user.Password
            };

            var valideUser = new MayBe<MiamUser>(user);
            _userAccountService.ValidateUser(loginViewModel.Email, loginViewModel.Password).Returns(valideUser);

            //Action
            var routeResult = _accountController.Login(loginViewModel) as RedirectToRouteResult;
            var routeAction = routeResult.RouteValues["Action"];

            //Assert
            routeAction.Should().Be(MVC.Home.Views.ViewNames.Index);
        }