Example #1
0
        public async Task Login_Should_Return_ViewResult_With_Errors_After_Unsuccessful_Credentials_Verification_When_Account_Is_Not_Found()
        {
            var localLoginRequest = new LocalLoginRequest
            {
                Email         = "*****@*****.**",
                Password      = "******",
                RememberLogin = false,
                ReturnUrl     = "~/"
            };
            var localLoginResultOutputErrors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var localLoginResultOutput = LocalLoginResultOutput.Fail(false, localLoginResultOutputErrors);
            var externalProviders      = new List <LocalLoginExternalProviderOutput>
            {
                new LocalLoginExternalProviderOutput("google", AuthenticationExtension.GoogleAuthScheme),
                new LocalLoginExternalProviderOutput("facebook", AuthenticationExtension.FacebookAuthScheme)
            };
            var localLoginOutput            = new LocalLoginOutput(true, externalProviders);
            var expectedLocalLoginViewModel =
                new LocalLoginViewModel(true, true, true, string.Empty, string.Empty, string.Empty)
            {
                ReturnUrl     = localLoginRequest.ReturnUrl,
                Email         = localLoginRequest.Email,
                Password      = localLoginRequest.Password,
                RememberLogin = localLoginRequest.RememberLogin
            };
            var localLoginViewModelErrors = new List <string> {
                LocalLoginErrorMessage.InvalidCredentials
            };

            expectedLocalLoginViewModel.SetErrors(localLoginViewModelErrors);

            _localLoginInteractorMock
            .Setup(x => x.ExecuteAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(),
                                       It.IsAny <string>())).ReturnsAsync(localLoginResultOutput);
            _localLoginInteractorMock.Setup(x => x.ExecuteAsync(It.IsAny <string>())).ReturnsAsync(localLoginOutput);

            var result = await _controller.Login(localLoginRequest);

            var viewResult = result.As <ViewResult>();

            viewResult.Model.Should().BeEquivalentTo(expectedLocalLoginViewModel);
        }
Example #2
0
        public async Task ExecuteAsync_Should_Return_LocalLoginResultOutput_With_Fail_When_Account_Does_Not_Exist()
        {
            const string redirectUri = "http://localhost";
            var          authRequest = new AuthorizationRequest("idP", "clientId", redirectUri);
            var          errors      = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            var expectedResult = LocalLoginResultOutput.Fail(true, errors);

            _authorizationServiceMock.Setup(x => x.GetAuthorizationRequestAsync(It.IsAny <string>()))
            .ReturnsAsync(authRequest);
            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);

            var result = await _localLoginInteractor.ExecuteAsync("*****@*****.**", "Password", true, redirectUri);

            result.Should().BeEquivalentTo(expectedResult);
        }
Example #3
0
        public async Task ExecuteAsync_Should_Return_LocalLoginResultOutput_With_Fail_When_Account_Cannot_Be_Authenticated()
        {
            const string redirectUri = "http://localhost";
            var          authRequest = new AuthorizationRequest("idP", "clientId", redirectUri);
            var          account     = Account.Builder()
                                       .SetId(Guid.NewGuid())
                                       .SetEmail("*****@*****.**")
                                       .SetConfirmed(true)
                                       .SetPasswordHash("PasswordHash")
                                       .SetSecurityStamp(Guid.NewGuid())
                                       .SetCreated(DateTimeOffset.UtcNow)
                                       .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                                       .Build();
            var getAccountResult = GetResult <Account> .Ok(account);

            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotConfirmed, AccountErrorMessage.NotConfirmed)
            };
            var accountCanBeAuthenticatedVerificationResult = VerificationResult.Fail(errors);
            var expectedResult = LocalLoginResultOutput.Fail(true, errors);

            _authorizationServiceMock.Setup(x => x.GetAuthorizationRequestAsync(It.IsAny <string>()))
            .ReturnsAsync(authRequest);
            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);
            _accountVerificationServiceMock
            .Setup(x => x.VerifyAccountCanBeAuthenticated(It.IsAny <Account>(), It.IsAny <string>()))
            .Returns(accountCanBeAuthenticatedVerificationResult);

            var result = await _localLoginInteractor.ExecuteAsync("*****@*****.**", "Password", true, redirectUri);

            result.Should().BeEquivalentTo(expectedResult);
        }