Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given not null request
/// and password update has failed
/// when updating user password
/// return error message
/// </summary>
Given not null request
and password update has failed
when updating user password
return error message
Given not null request and password update has failed when updating user password return error message
[Fact]
        public async Task UpdateUserPasswordAsync_RequestNotNull_FailingUpdate_ReturnErrorMessage()
        {
            PasswordInitializationRequest request = new PasswordInitializationRequest
            {
                Login = "Homer",
                OldPassword = "Hold my beer",
                NewPassword = "thank you moe"
            };
            User identityUser = new User
            {
                UserName = request.Login
            };
            string errorMessage = "stupid flanders";
            _userManagerMock.Setup(mock => mock.FindByNameAsync(request.Login)).ReturnsAsync(identityUser);
            _userManagerMock.Setup(mock => mock.ChangePasswordAsync(identityUser, request.OldPassword, request.NewPassword))
                .ReturnsAsync(IdentityResult.Failed(new IdentityError { Description = errorMessage }));
            ResultMessage resultMessage = await _identityService.UpdateUserPasswordAsync(request).ConfigureAwait(false);
            Assert.NotNull(resultMessage);
            Assert.False(resultMessage.OperationStatus);
            Assert.Equal(errorMessage, resultMessage.ErrorMessages.First());
        }
[ Fact ] public async Task UpdateUserPasswordAsync_RequestNotNull_FailingUpdate_ReturnErrorMessage ( ) { PasswordInitializationRequest request = new PasswordInitializationRequest { Login = " " , OldPassword = " " , NewPassword = " " } ; User identityUser = new User { UserName = request . Login } ; string errorMessage = " " ; _userManagerMock . Setup ( mock => mock . FindByNameAsync ( request . Login ) ) . ReturnsAsync ( identityUser ) ; _userManagerMock . Setup ( mock => mock . ChangePasswordAsync ( identityUser , request . OldPassword , request . NewPassword ) ) . ReturnsAsync ( IdentityResult . Failed ( new IdentityError { Description = errorMessage } ) ) ; ResultMessage resultMessage = await _identityService . UpdateUserPasswordAsync ( request ) . ConfigureAwait ( false ) ; Assert . NotNull ( resultMessage ) ; Assert . False ( resultMessage . OperationStatus ) ; Assert . Equal ( errorMessage , resultMessage . ErrorMessages . First ( ) ) ; }
Given not null request
and password update has failed
when updating user password
return error message
Given not null request and password update has failed when updating user password return error message
// Arrange // Act // Assert