Esempio n. 1
0
        public async Task Login_LoginViewModel_FailedSignIn_AddsDisabledValidationError()
        {
            const string email       = "*****@*****.**";
            const string phoneNumber = "012345678901";

            var disabledSetting = new DisabledErrorMessageSettings()
            {
                EmailAddress = email,
                PhoneNumber  = phoneNumber
            };

            using var controller = AccountControllerBuilder
                                   .Create()
                                   .WithSignInResult(Result.Failure <SignInResponse>(new List <ErrorDetails> { LoginUserErrors.UserIsDisabled() }))
                                   .WithDisabledErrorMessageSetting(disabledSetting)
                                   .Build();

            await controller.Login(LoginViewModelBuilder.Create().Build());

            var modelState = controller.ModelState;

            modelState.IsValid.Should().BeFalse();
            modelState.Count.Should().Be(1);

            (string key, ModelStateEntry entry) = modelState.First();
            key.Should().Be(nameof(LoginViewModel.DisabledError));
            entry.Errors.Count.Should().Be(1);
            var expected = string.Format(CultureInfo.CurrentCulture, AccountController.UserDisabledErrorMessageTemplate, email,
                                         phoneNumber);

            entry.Errors.First().ErrorMessage.Should().Be(expected);
        }
Esempio n. 2
0
        public async Task Login_LoginViewModel_InvalidViewModelWithValues_ReturnsExpectedView()
        {
            const string loginHint = "LoginHint";

            var uri = new Uri("http://www.foobar.com/");

            var inputModel = LoginViewModelBuilder
                             .Create()
                             .WithEmailAddress("NotLoginHint")
                             .WithReturnUrl(uri)
                             .WithPassword("Password")
                             .Build();

            using var controller = AccountControllerBuilder
                                   .Create()
                                   .WithSignInResult(new Result <SignInResponse>(false, null, new SignInResponse(false, loginHint: loginHint)))
                                   .Build();

            controller.ModelState.AddModelError(string.Empty, "Fake error!");

            var result = await controller.Login(inputModel) as ViewResult;

            Assert.NotNull(result);

            var viewModel = result.Model as LoginViewModel;

            Assert.NotNull(viewModel);
            viewModel.ReturnUrl.Should().BeEquivalentTo(uri);
            viewModel.Password.Should().BeNull();
            viewModel.EmailAddress.Should().BeEquivalentTo(loginHint);
        }
Esempio n. 3
0
            static async Task Login()
            {
                using var controller = AccountControllerBuilder
                                       .Create()
                                       .Build();

                await controller.Login((LoginViewModel)null);
            }
Esempio n. 4
0
        public async Task Login_LoginViewModel_FailedSignIn_ReturnsExpectedView()
        {
            using var controller = AccountControllerBuilder
                                   .Create()
                                   .WithSignInResult(Result.Failure <SignInResponse>(new List <ErrorDetails>()))
                                   .Build();

            var result = await controller.Login(LoginViewModelBuilder.Create().Build()) as ViewResult;

            Assert.NotNull(result);

            var viewModel = result.Model as LoginViewModel;

            Assert.NotNull(viewModel);
        }
Esempio n. 5
0
        public async Task Login_LoginViewModel_FailedSignIn_AddsUsernameOrPasswordValidationError()
        {
            using var controller = AccountControllerBuilder
                                   .Create()
                                   .WithSignInResult(Result.Failure <SignInResponse>(new List <ErrorDetails> { LoginUserErrors.UserNameOrPasswordIncorrect() }))
                                   .Build();

            await controller.Login(LoginViewModelBuilder.Create().Build());

            var modelState = controller.ModelState;

            modelState.IsValid.Should().BeFalse();
            modelState.Count.Should().Be(2);

            foreach ((string key, ModelStateEntry entry) in modelState)
            {
                entry.Errors.Count.Should().Be(1);
                entry.Errors.First().ErrorMessage.Should().Be(AccountController.SignInErrorMessage);
            }
        }
Esempio n. 6
0
        public async Task Login_LoginViewModel_InvalidViewModel_WithoutEmailAddressAndPassword__ReturnsExpectedView()
        {
            using var controller = AccountControllerBuilder
                                   .Create()
                                   .WithSignInResult(Result.Failure <SignInResponse>(new List <ErrorDetails>()))
                                   .Build();

            controller.ModelState.AddModelError(string.Empty, "Fake error!");

            var inputModel = LoginViewModelBuilder
                             .Create()
                             .Build();

            var result = await controller.Login(inputModel) as ViewResult;

            Assert.NotNull(result);

            var viewModel = result.Model as LoginViewModel;

            Assert.NotNull(viewModel);
            viewModel.ReturnUrl.Should().Be(inputModel.ReturnUrl);
            viewModel.Password.Should().BeNull();
            viewModel.EmailAddress.Should().BeNull();
        }