Пример #1
0
        public void ShouldAddErrorAndRedirectWhenLoginFails()
        {
            var loginModel = new LoginModel { Email = "email", Password = "******", RememberMe = true };
            _accountService.Setup(it => it.Login("email", "password", true)).Returns(false);

            var result = (ViewResult) _accountController.Login(loginModel, "someUrl");

            _accountController.ModelState.IsValid.Should().BeFalse("there should be an error added to the ModelState");
            result.Model.Should().Be(loginModel);
        }
Пример #2
0
        public void ShouldAddErrorAndRedirectWhenModelIsInvalid()
        {
            var loginModel = new LoginModel { Email = "email", Password = "******", RememberMe = true };
            _accountService.Setup(it => it.Login("email", "password", true)).Returns(true);
            _accountController.ModelState.AddModelError("something", "Error");

            var result = _accountController.Login(loginModel, "someUrl");

            _accountController.ModelState.IsValid.Should().BeFalse("there should be an error added to the ModelState");
            result.Should().BeOfType<ViewResult>();
            ((ViewResult)result).Model.Should().Be(loginModel);
        }
Пример #3
0
        public void ShouldLogInUserWhenModelStateIsValid()
        {
            var loginModel = new LoginModel{ Email = "email", Password = "******", RememberMe = true};
            _accountService.Setup(it => it.Login("email", "password", true)).Returns(true);

            _accountController.Login(loginModel, "someUrl");

            _accountService.Verify(it => it.Login("email", "password", true));
        }