Skip to content

Commit

Permalink
Revised tests for IdentityUserIntegrationService
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed Sep 26, 2023
1 parent 7a29bb4 commit ced61b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
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()
{
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();
}

Expand All @@ -41,28 +53,28 @@ public async Task FindByUserNameAsync()
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");
}

[Fact]
public async Task Search_With_Filter()
{
var result = await _identityUserLookupAppService.SearchAsync(
var result = await _identityUserIntegrationService.SearchAsync(
new UserLookupSearchInputDto
{
Filter = "a"
Expand All @@ -73,7 +85,7 @@ public async Task Search_With_Filter()
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"
Expand Down

0 comments on commit ced61b4

Please sign in to comment.