|
|
@ -1,8 +1,10 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Shouldly; |
|
|
using Shouldly; |
|
|
using Volo.Abp.Application.Dtos; |
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.Identity |
|
|
namespace Volo.Abp.Identity |
|
|
@ -10,10 +12,12 @@ namespace Volo.Abp.Identity |
|
|
public class IdentityUserAppService_Tests : AbpIdentityApplicationTestBase |
|
|
public class IdentityUserAppService_Tests : AbpIdentityApplicationTestBase |
|
|
{ |
|
|
{ |
|
|
private readonly IIdentityUserAppService _identityUserAppService; |
|
|
private readonly IIdentityUserAppService _identityUserAppService; |
|
|
|
|
|
private readonly IRepository<IdentityUser> _userRepository; |
|
|
|
|
|
|
|
|
public IdentityUserAppService_Tests() |
|
|
public IdentityUserAppService_Tests() |
|
|
{ |
|
|
{ |
|
|
_identityUserAppService = ServiceProvider.GetRequiredService<IIdentityUserAppService>(); |
|
|
_identityUserAppService = ServiceProvider.GetRequiredService<IIdentityUserAppService>(); |
|
|
|
|
|
_userRepository = ServiceProvider.GetRequiredService<IRepository<IdentityUser>>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -27,24 +31,87 @@ namespace Volo.Abp.Identity |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task CreateAsync() |
|
|
public async Task CreateAsync() |
|
|
{ |
|
|
{ |
|
|
var input = new IdentityUserCreateOrUpdateDto |
|
|
//Arrange
|
|
|
|
|
|
|
|
|
|
|
|
var input = new IdentityUserCreateDto |
|
|
{ |
|
|
{ |
|
|
UserName = Guid.NewGuid().ToString(), |
|
|
UserName = Guid.NewGuid().ToString(), |
|
|
Email = Guid.NewGuid().ToString("N").Left(16) + "@abp.io", |
|
|
Email = CreateRandomEmail(), |
|
|
LockoutEnabled = true, |
|
|
LockoutEnabled = true, |
|
|
PhoneNumber = RandomHelper.GetRandom(10000000,100000000).ToString(), |
|
|
PhoneNumber = CreateRandomPhoneNumber(), |
|
|
Password = "123qwe" |
|
|
Password = "123qwe" |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
|
|
|
|
var result = await _identityUserAppService.CreateAsync(input); |
|
|
var result = await _identityUserAppService.CreateAsync(input); |
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
|
|
|
|
result.Id.ShouldNotBe(Guid.Empty); |
|
|
result.Id.ShouldNotBe(Guid.Empty); |
|
|
result.UserName.ShouldBe(input.UserName); |
|
|
result.UserName.ShouldBe(input.UserName); |
|
|
result.Email.ShouldBe(input.Email); |
|
|
result.Email.ShouldBe(input.Email); |
|
|
result.LockoutEnabled.ShouldBe(input.LockoutEnabled); |
|
|
result.LockoutEnabled.ShouldBe(input.LockoutEnabled); |
|
|
result.PhoneNumber.ShouldBe(input.PhoneNumber); |
|
|
result.PhoneNumber.ShouldBe(input.PhoneNumber); |
|
|
|
|
|
|
|
|
//TODO: Also check repository
|
|
|
var user = await _userRepository.GetAsync(result.Id); |
|
|
|
|
|
user.Id.ShouldBe(result.Id); |
|
|
|
|
|
user.UserName.ShouldBe(input.UserName); |
|
|
|
|
|
user.Email.ShouldBe(input.Email); |
|
|
|
|
|
user.LockoutEnabled.ShouldBe(input.LockoutEnabled); |
|
|
|
|
|
user.PhoneNumber.ShouldBe(input.PhoneNumber); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task UpdateAsync() |
|
|
|
|
|
{ |
|
|
|
|
|
//Arrange
|
|
|
|
|
|
|
|
|
|
|
|
var johnNash = await GetUserAsync("john.nash"); |
|
|
|
|
|
|
|
|
|
|
|
var input = new IdentityUserUpdateDto |
|
|
|
|
|
{ |
|
|
|
|
|
UserName = johnNash.UserName, |
|
|
|
|
|
LockoutEnabled = true, |
|
|
|
|
|
TwoFactorEnabled = true, |
|
|
|
|
|
PhoneNumber = CreateRandomPhoneNumber(), |
|
|
|
|
|
Email = CreateRandomEmail() |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
|
|
|
|
|
|
|
var result = await _identityUserAppService.UpdateAsync(johnNash.Id, input); |
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
|
|
|
|
|
|
|
result.Id.ShouldBe(johnNash.Id); |
|
|
|
|
|
result.UserName.ShouldBe(input.UserName); |
|
|
|
|
|
result.Email.ShouldBe(input.Email); |
|
|
|
|
|
result.LockoutEnabled.ShouldBe(input.LockoutEnabled); |
|
|
|
|
|
result.PhoneNumber.ShouldBe(input.PhoneNumber); |
|
|
|
|
|
|
|
|
|
|
|
var user = await _userRepository.GetAsync(result.Id); |
|
|
|
|
|
user.Id.ShouldBe(result.Id); |
|
|
|
|
|
user.UserName.ShouldBe(input.UserName); |
|
|
|
|
|
user.Email.ShouldBe(input.Email); |
|
|
|
|
|
user.LockoutEnabled.ShouldBe(input.LockoutEnabled); |
|
|
|
|
|
user.PhoneNumber.ShouldBe(input.PhoneNumber); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<IdentityUser> GetUserAsync(string userName) |
|
|
|
|
|
{ |
|
|
|
|
|
return (await _userRepository.GetListAsync()).First(u => u.UserName == userName); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static string CreateRandomEmail() |
|
|
|
|
|
{ |
|
|
|
|
|
return Guid.NewGuid().ToString("N").Left(16) + "@abp.io"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static string CreateRandomPhoneNumber() |
|
|
|
|
|
{ |
|
|
|
|
|
return RandomHelper.GetRandom(10000000, 100000000).ToString(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|