diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/ProfileAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/ProfileAppService.cs index 88d2ccbf5a..9749a607d5 100644 --- a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/ProfileAppService.cs +++ b/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)) { (await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/ProfileAppService_Tests.cs b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/ProfileAppService_Tests.cs index d5536c9ad9..62ad4e4bc8 100644 --- a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/ProfileAppService_Tests.cs +++ b/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); } + [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] public async Task ChangePasswordAsync_FailsForSamePassword() {