Browse Source

Revised tests for IdentityUserIntegrationService

pull/17737/head
Halil İbrahim Kalkan 2 years ago
parent
commit
ced61b41d0
  1. 1
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs
  3. 36
      modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/Integration/IdentityUserIntegrationService_Tests.cs

1
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs

@ -6,6 +6,7 @@ using Volo.Abp.Users;
namespace Volo.Abp.Identity;
[Obsolete("Use IIdentityUserIntegrationService for module-to-module (or service-to-service) communication.")]
public interface IIdentityUserLookupAppService : IApplicationService
{
Task<UserData> FindByIdAsync(Guid id);

2
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs

@ -7,7 +7,7 @@ using Volo.Abp.Users;
namespace Volo.Abp.Identity;
[Obsolete("Use IIdentityUserIntegrationService for module-to-module (or service-to-service) communication.")]
[Obsolete("Use IdentityUserIntegrationService for module-to-module (or service-to-service) communication.")]
[Authorize(IdentityPermissions.UserLookup.Default)]
public class IdentityUserLookupAppService : IdentityAppServiceBase, IIdentityUserLookupAppService
{

36
modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserLookupAppService_Tests.cs → modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/Integration/IdentityUserIntegrationService_Tests.cs

@ -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"
Loading…
Cancel
Save