Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given not null request
/// And user role is not admin
/// and removing old password is not executed successfully
/// when initializing user password
/// return error message
/// </summary>
Given not null request
And user role is not admin
and removing old password is not executed successfully
when initializing user password
return error message
Given not null request And user role is not admin and removing old password is not executed successfully when initializing user password return error message
[Fact]
        public async Task InitializeUserPassword_NotNullRequest_NotAdminRole_FailingOldPasswordRemoving_ReturnErrorMessage()
        {
            PasswordInitializationRequest request = new PasswordInitializationRequest
            {
                Login = "bart",
                NewPassword = "elBarto253",
                OldPassword = "elBarto659"
            };
            User identityUser = new User
            {
                UserName = request.Login
            };
            string errorMessage = "you suck";
            _userManagerMock.Setup(mock => mock.FindByNameAsync(request.Login)).ReturnsAsync(identityUser);
            _userManagerMock.Setup(mock => mock.GetRolesAsync(identityUser)).ReturnsAsync(new List<string>
                { "littleKid" });
            _userManagerMock.Setup(mock => mock.RemovePasswordAsync(identityUser)).ReturnsAsync(
                IdentityResult.Failed(new IdentityError { Description = errorMessage }));
            ResultMessage result = await _identityService.InitializeUserPasswordAsync(request).ConfigureAwait(false);
            Assert.NotNull(result);
            Assert.False(result.OperationStatus);
            Assert.Equal(errorMessage, result.ErrorMessages.First());
        }
[ Fact ] public async Task InitializeUserPassword_NotNullRequest_NotAdminRole_FailingOldPasswordRemoving_ReturnErrorMessage ( ) { PasswordInitializationRequest request = new PasswordInitializationRequest { Login = " " , NewPassword = " " , OldPassword = " " } ; User identityUser = new User { UserName = request . Login } ; string errorMessage = " " ; _userManagerMock . Setup ( mock => mock . FindByNameAsync ( request . Login ) ) . ReturnsAsync ( identityUser ) ; _userManagerMock . Setup ( mock => mock . GetRolesAsync ( identityUser ) ) . ReturnsAsync ( new List < string > { " " } ) ; _userManagerMock . Setup ( mock => mock . RemovePasswordAsync ( identityUser ) ) . ReturnsAsync ( IdentityResult . Failed ( new IdentityError { Description = errorMessage } ) ) ; ResultMessage result = await _identityService . InitializeUserPasswordAsync ( request ) . ConfigureAwait ( false ) ; Assert . NotNull ( result ) ; Assert . False ( result . OperationStatus ) ; Assert . Equal ( errorMessage , result . ErrorMessages . First ( ) ) ; }
Given not null request
And user role is not admin
and removing old password is not executed successfully
when initializing user password
return error message
Given not null request And user role is not admin and removing old password is not executed successfully when initializing user password return error message
// Arrange // Act // Assert