Browse Source

Merge pull request #18833 from abpframework/ProfileAppService

Should not update user's `PhoneNumber ` if input's `PhoneNumber`  is `NullOrWhiteSpace`.
pull/18835/head
liangshiwei 3 years ago
committed by GitHub
parent
commit
18b12c6925
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/ProfileAppService.cs
  2. 30
      modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/ProfileAppService_Tests.cs

5
modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/ProfileAppService.cs

@ -58,6 +58,11 @@ public class ProfileAppService : IdentityAppServiceBase, IProfileAppService
} }
} }
if (user.PhoneNumber.IsNullOrWhiteSpace() && input.PhoneNumber.IsNullOrWhiteSpace())
{
input.PhoneNumber = user.PhoneNumber;
}
if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase)) if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase))
{ {
(await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); (await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors();

30
modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/ProfileAppService_Tests.cs

@ -73,6 +73,36 @@ public class ProfileAppService_Tests : AbpAccountApplicationTestBase
result.Name.ShouldBe(input.Name); result.Name.ShouldBe(input.Name);
} }
[Fact]
public async Task Should_Not_UpdatePhoneNumber_If_Input_PhoneNumber_IsNullOrWhiteSpace_Test()
{
//Arrange
_currentUser.Id.Returns(_testData.UserJohnId);
_currentUser.IsAuthenticated.Returns(true);
//Act
var result = await _profileAppService.UpdateAsync(new UpdateProfileDto
{
UserName = CreateRandomString(),
Email = CreateRandomEmail(),
PhoneNumber = ""
});
//Assert
result.PhoneNumber.ShouldBe(null);
//Act
result = await _profileAppService.UpdateAsync(new UpdateProfileDto
{
UserName = CreateRandomString(),
Email = CreateRandomEmail(),
PhoneNumber = "123"
});
//Assert
result.PhoneNumber.ShouldBe("123");
}
[Fact] [Fact]
public async Task ChangePasswordAsync_FailsForSamePassword() public async Task ChangePasswordAsync_FailsForSamePassword()
{ {

Loading…
Cancel
Save