Tests/Identity.Infrastructure.Tests/Services/IdentityServiceTests.cs
/// <summary>
/// Given not null request
/// And user role is not admin
/// and operation is executed successfully
/// when initializing user password
/// return success message
/// </summary>
Given not null request
And user role is not admin
and operation is executed successfully
when initializing user password
return success message
Given not null request And user role is not admin and operation is executed successfully when initializing user password return success message
[Fact]
        public async Task InitializeUserPassword_NotNullRequest_NotAdminRole_SuccessOperation_ReturnSuccessMessage()
        {
            PasswordInitializationRequest request = new PasswordInitializationRequest
            {
                Login = "bart",
                NewPassword = "elBarto253",
                OldPassword = "elBarto659"
            };
            User identityUser = new User
            {
                UserName = request.Login
            };
            _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.Success);
            _userManagerMock.Setup(mock => mock.AddPasswordAsync(identityUser, request.NewPassword)).ReturnsAsync(IdentityResult.Success);
            ResultMessage result = await _identityService.InitializeUserPasswordAsync(request).ConfigureAwait(false);
            Assert.NotNull(result);
            Assert.True(result.OperationStatus);
        }
[ Fact ] public async Task InitializeUserPassword_NotNullRequest_NotAdminRole_SuccessOperation_ReturnSuccessMessage ( ) { PasswordInitializationRequest request = new PasswordInitializationRequest { Login = " " , NewPassword = " " , OldPassword = " " } ; User identityUser = new User { UserName = request . Login } ; _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 . Success ) ; _userManagerMock . Setup ( mock => mock . AddPasswordAsync ( identityUser , request . NewPassword ) ) . ReturnsAsync ( IdentityResult . Success ) ; ResultMessage result = await _identityService . InitializeUserPasswordAsync ( request ) . ConfigureAwait ( false ) ; Assert . NotNull ( result ) ; Assert . True ( result . OperationStatus ) ; }
Given not null request
And user role is not admin
and operation is executed successfully
when initializing user password
return success message
Given not null request And user role is not admin and operation is executed successfully when initializing user password return success message
// Arrange // Act // Assert