Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given a not null request
/// and creation failed
/// when creating new user
/// return failing result message
/// </summary>
Given a not null request
and creation failed
when creating new user
return failing result message
Given a not null request and creation failed when creating new user return failing result message
[Fact]
        public async Task CreateUserAsync_GivenNotNullRequest_CreationFailed_ReturnFailingMessage()
        {
            UserCreationRequest request = new UserCreationRequest
            {
                Email = "nana@hotmail.com",
                Login = "nani",
                Password = "screwyouPass"
            };
            string errorMessage = "hate my life";
            IdentityResult identityResult = IdentityResult.Failed(new IdentityError
            {
                Code = "23",
                Description = errorMessage
            });
            _userManagerMock.Setup(mock => mock.CreateAsync(It.Is<User>(user => user.Email == request.Email
                && user.UserName == request.Login), request.Password)).ReturnsAsync(identityResult);
            ResultMessage result = await _identityService.CreateUserAsync(request).ConfigureAwait(false);
            Assert.NotNull(result);
            Assert.False(result.OperationStatus);
            Assert.Equal(errorMessage, result.ErrorMessages.First());
        }
[ Fact ] public async Task CreateUserAsync_GivenNotNullRequest_CreationFailed_ReturnFailingMessage ( ) { UserCreationRequest request = new UserCreationRequest { Email = " " , Login = " " , Password = " " } ; string errorMessage = " " ; IdentityResult identityResult = IdentityResult . Failed ( new IdentityError { Code = " " , Description = errorMessage } ) ; _userManagerMock . Setup ( mock => mock . CreateAsync ( It . Is < User > ( user => user . Email == request . Email && user . UserName == request . Login ) , request . Password ) ) . ReturnsAsync ( identityResult ) ; ResultMessage result = await _identityService . CreateUserAsync ( request ) . ConfigureAwait ( false ) ; Assert . NotNull ( result ) ; Assert . False ( result . OperationStatus ) ; Assert . Equal ( errorMessage , result . ErrorMessages . First ( ) ) ; }
Given a not null request
and creation failed
when creating new user
return failing result message
Given a not null request and creation failed when creating new user return failing result message
// Arrange // Act // Assert