Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given valid request
/// And a successful authentication
/// When authenticating user
/// Return success authentification result
/// </summary>
Given valid request
And a successful authentication
When authenticating user
Return success authentification result
Given valid request And a successful authentication When authenticating user Return success authentification result
[Fact]
        public async Task AuthenticateUserAsync_GivenValidRequestAndSuccessfulAuthentication_ReturnSuccessAuthResult()
        {
            AuthenticationRequest authentificationRequest = new AuthenticationRequest
            {
                Login = "blablaUser",
                Password = "pif/paf/piao"
            };
            User identityUser = new User
            {
                Id = 1,
                UserName = authentificationRequest.Login
            };
            _userManagerMock.Setup(mock => mock.FindByNameAsync(authentificationRequest.Login)).ReturnsAsync(identityUser);
            _signInManagerMock.Setup(mock => mock.CheckPasswordSignInAsync(It.IsAny<User>(), authentificationRequest.Password, false)).ReturnsAsync(SignInResult.Success);
            _userManagerMock.Setup(mock => mock.GetRolesAsync(identityUser)).ReturnsAsync(new List<string> { "pifUserRole" });
            AuthenticationResult result = await _identityService.AuthenticateUserAsync(authentificationRequest).ConfigureAwait(false);
            Assert.NotNull(result);
            Assert.True(result.OperationStatus);
            Assert.True(!string.IsNullOrEmpty(result.Token));
            Assert.Empty(result.ErrorMessages);
        }
[ Fact ] public async Task AuthenticateUserAsync_GivenValidRequestAndSuccessfulAuthentication_ReturnSuccessAuthResult ( ) { AuthenticationRequest authentificationRequest = new AuthenticationRequest { Login = " " , Password = " " } ; User identityUser = new User { Id = 1 , UserName = authentificationRequest . Login } ; _userManagerMock . Setup ( mock => mock . FindByNameAsync ( authentificationRequest . Login ) ) . ReturnsAsync ( identityUser ) ; _signInManagerMock . Setup ( mock => mock . CheckPasswordSignInAsync ( It . IsAny < User > ( ) , authentificationRequest . Password , false ) ) . ReturnsAsync ( SignInResult . Success ) ; _userManagerMock . Setup ( mock => mock . GetRolesAsync ( identityUser ) ) . ReturnsAsync ( new List < string > { " " } ) ; AuthenticationResult result = await _identityService . AuthenticateUserAsync ( authentificationRequest ) . ConfigureAwait ( false ) ; Assert . NotNull ( result ) ; Assert . True ( result . OperationStatus ) ; Assert . True ( ! string . IsNullOrEmpty ( result . Token ) ) ; Assert . Empty ( result . ErrorMessages ) ; }
Given valid request
And a successful authentication
When authenticating user
Return success authentification result
Given valid request And a successful authentication When authenticating user Return success authentification result
// Arrange // Act // Assert