|
|
|
@ -1,23 +1,35 @@ |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
using Shouldly; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity; |
|
|
|
namespace Volo.Abp.Identity.Integration; |
|
|
|
|
|
|
|
public class IdentityUserLookupAppService_Tests : AbpIdentityApplicationTestBase |
|
|
|
public class IdentityUserIntegrationService_Tests : AbpIdentityApplicationTestBase |
|
|
|
{ |
|
|
|
private readonly IIdentityUserLookupAppService _identityUserLookupAppService; |
|
|
|
private readonly IIdentityUserIntegrationService _identityUserIntegrationService; |
|
|
|
private readonly IIdentityUserRepository _identityUserRepository; |
|
|
|
private readonly ILookupNormalizer _lookupNormalizer; |
|
|
|
|
|
|
|
public IdentityUserLookupAppService_Tests() |
|
|
|
public IdentityUserIntegrationService_Tests() |
|
|
|
{ |
|
|
|
_identityUserLookupAppService = GetRequiredService<IIdentityUserLookupAppService>(); |
|
|
|
_identityUserIntegrationService = GetRequiredService<IIdentityUserIntegrationService>(); |
|
|
|
_identityUserRepository = GetRequiredService<IIdentityUserRepository>(); |
|
|
|
_lookupNormalizer = GetRequiredService<ILookupNormalizer>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task GetRoleNamesAsync() |
|
|
|
{ |
|
|
|
var adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("admin")); |
|
|
|
adminUser.ShouldNotBeNull(); |
|
|
|
|
|
|
|
var roles = await _identityUserIntegrationService.GetRoleNamesAsync(adminUser.Id); |
|
|
|
roles.Length.ShouldBe(1); |
|
|
|
roles.ShouldContain("admin"); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task FindByIdAsync() |
|
|
|
@ -25,13 +37,13 @@ public class IdentityUserLookupAppService_Tests : AbpIdentityApplicationTestBase |
|
|
|
var user = await _identityUserRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("john.nash")); |
|
|
|
user.ShouldNotBeNull(); |
|
|
|
|
|
|
|
(await _identityUserLookupAppService.FindByIdAsync(user.Id)).UserName.ShouldBe(user.UserName); |
|
|
|
(await _identityUserIntegrationService.FindByIdAsync(user.Id)).UserName.ShouldBe(user.UserName); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task FindById_NotExist_Should_Return_Null() |
|
|
|
{ |
|
|
|
var user = await _identityUserLookupAppService.FindByIdAsync(Guid.NewGuid()); |
|
|
|
var user = await _identityUserIntegrationService.FindByIdAsync(Guid.NewGuid()); |
|
|
|
user.ShouldBeNull(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -41,20 +53,20 @@ public class IdentityUserLookupAppService_Tests : AbpIdentityApplicationTestBase |
|
|
|
var user = await _identityUserRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("john.nash")); |
|
|
|
user.ShouldNotBeNull(); |
|
|
|
|
|
|
|
(await _identityUserLookupAppService.FindByUserNameAsync(user.UserName)).UserName.ShouldBe(user.UserName); |
|
|
|
(await _identityUserIntegrationService.FindByUserNameAsync(user.UserName)).UserName.ShouldBe(user.UserName); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task FindByUserName_NotExist_Should_Return_Null() |
|
|
|
{ |
|
|
|
var user = await _identityUserLookupAppService.FindByUserNameAsync(Guid.NewGuid().ToString()); |
|
|
|
var user = await _identityUserIntegrationService.FindByUserNameAsync(Guid.NewGuid().ToString()); |
|
|
|
user.ShouldBeNull(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Search_Without_Filter_And_Sorting() |
|
|
|
{ |
|
|
|
var result = await _identityUserLookupAppService.SearchAsync(new UserLookupSearchInputDto()); |
|
|
|
var result = await _identityUserIntegrationService.SearchAsync(new UserLookupSearchInputDto()); |
|
|
|
result.Items.Count.ShouldBeGreaterThanOrEqualTo(3); |
|
|
|
result.Items.ShouldContain(u => u.UserName == "john.nash"); |
|
|
|
} |
|
|
|
@ -62,7 +74,7 @@ public class IdentityUserLookupAppService_Tests : AbpIdentityApplicationTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Search_With_Filter() |
|
|
|
{ |
|
|
|
var result = await _identityUserLookupAppService.SearchAsync( |
|
|
|
var result = await _identityUserIntegrationService.SearchAsync( |
|
|
|
new UserLookupSearchInputDto |
|
|
|
{ |
|
|
|
Filter = "a" |
|
|
|
@ -73,7 +85,7 @@ public class IdentityUserLookupAppService_Tests : AbpIdentityApplicationTestBase |
|
|
|
result.Items.ShouldContain(u => u.UserName == "john.nash"); |
|
|
|
result.Items.ShouldContain(u => u.UserName == "david"); |
|
|
|
|
|
|
|
result = await _identityUserLookupAppService.SearchAsync( |
|
|
|
result = await _identityUserIntegrationService.SearchAsync( |
|
|
|
new UserLookupSearchInputDto |
|
|
|
{ |
|
|
|
Filter = "neo" |