Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given valid request
/// And a failing authentication
/// When authenticating user
/// Return error authentification result
/// </summary>
Given valid request
And a failing authentication
When authenticating user
Return error authentification result
Given valid request And a failing authentication When authenticating user Return error authentification result
[Fact]
        public async Task AuthenticateUserAsync_GivenValidRequestAndFailingAuthentication_ReturnErrorAuthResult()
        {
            AuthenticationRequest authentificationRequest = new AuthenticationRequest
            {
                Login = "blablaUser",
                Password = "pif/paf/piao"
            };
            _userManagerMock.Setup(mock => mock.FindByNameAsync(authentificationRequest.Login)).ReturnsAsync(new User
            {
                Id = 1,
                UserName = authentificationRequest.Login
            });
            _signInManagerMock.Setup(mock => mock.CheckPasswordSignInAsync(It.IsAny<User>(), authentificationRequest.Password, false)).ReturnsAsync(SignInResult.Failed);
            AuthenticationResult result = await _identityService.AuthenticateUserAsync(authentificationRequest).ConfigureAwait(false);
            Assert.NotNull(result);
            Assert.False(result.OperationStatus);
            Assert.NotEmpty(result.ErrorMessages);
            Assert.Equal(MessageResources.WrongCredentials, result.ErrorMessages.First());
        }
[ Fact ] public async Task AuthenticateUserAsync_GivenValidRequestAndFailingAuthentication_ReturnErrorAuthResult ( ) { AuthenticationRequest authentificationRequest = new AuthenticationRequest { Login = " " , Password = " " } ; _userManagerMock . Setup ( mock => mock . FindByNameAsync ( authentificationRequest . Login ) ) . ReturnsAsync ( new User { Id = 1 , UserName = authentificationRequest . Login } ) ; _signInManagerMock . Setup ( mock => mock . CheckPasswordSignInAsync ( It . IsAny < User > ( ) , authentificationRequest . Password , false ) ) . ReturnsAsync ( SignInResult . Failed ) ; AuthenticationResult result = await _identityService . AuthenticateUserAsync ( authentificationRequest ) . ConfigureAwait ( false ) ; Assert . NotNull ( result ) ; Assert . False ( result . OperationStatus ) ; Assert . NotEmpty ( result . ErrorMessages ) ; Assert . Equal ( MessageResources . WrongCredentials , result . ErrorMessages . First ( ) ) ; }
Given valid request
And a failing authentication
When authenticating user
Return error authentification result
Given valid request And a failing authentication When authenticating user Return error authentification result
// Arrange // Act // Assert