From 0e07100bcc65792f78d8b3f5b0f6fa88f2ed25de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 26 Sep 2023 10:12:52 +0300 Subject: [PATCH 1/4] Move methods fromIdentityUserLookupAppService to IdentityUserIntegrationService --- .../IIdentityUserIntegrationService.cs | 10 ++++ .../Identity/IdentityUserLookupAppService.cs | 39 +++----------- .../IdentityUserIntegrationService.cs | 52 ++++++++++++++++++- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs index e690b8bd0a..815c1c48c9 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs @@ -1,6 +1,8 @@ using System; using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.Abp.Users; namespace Volo.Abp.Identity.Integration; @@ -8,4 +10,12 @@ namespace Volo.Abp.Identity.Integration; public interface IIdentityUserIntegrationService : IApplicationService { Task GetRoleNamesAsync(Guid id); + + Task FindByIdAsync(Guid id); + + Task FindByUserNameAsync(string userName); + + Task> SearchAsync(UserLookupSearchInputDto input); + + Task GetCountAsync(UserLookupCountInputDto input); } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs index 4695517810..d8baff07ad 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs @@ -1,8 +1,8 @@ using System; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Dtos; +using Volo.Abp.Identity.Integration; using Volo.Abp.Users; namespace Volo.Abp.Identity; @@ -10,54 +10,31 @@ namespace Volo.Abp.Identity; [Authorize(IdentityPermissions.UserLookup.Default)] public class IdentityUserLookupAppService : IdentityAppServiceBase, IIdentityUserLookupAppService { - protected IdentityUserRepositoryExternalUserLookupServiceProvider UserLookupServiceProvider { get; } + protected IIdentityUserIntegrationService IdentityUserIntegrationService { get; } public IdentityUserLookupAppService( - IdentityUserRepositoryExternalUserLookupServiceProvider userLookupServiceProvider) + IIdentityUserIntegrationService identityUserIntegrationService) { - UserLookupServiceProvider = userLookupServiceProvider; + IdentityUserIntegrationService = identityUserIntegrationService; } public virtual async Task FindByIdAsync(Guid id) { - var userData = await UserLookupServiceProvider.FindByIdAsync(id); - if (userData == null) - { - return null; - } - - return new UserData(userData); + return await IdentityUserIntegrationService.FindByIdAsync(id); } public virtual async Task FindByUserNameAsync(string userName) { - var userData = await UserLookupServiceProvider.FindByUserNameAsync(userName); - if (userData == null) - { - return null; - } - - return new UserData(userData); + return await IdentityUserIntegrationService.FindByUserNameAsync(userName); } public virtual async Task> SearchAsync(UserLookupSearchInputDto input) { - var users = await UserLookupServiceProvider.SearchAsync( - input.Sorting, - input.Filter, - input.MaxResultCount, - input.SkipCount - ); - - return new ListResultDto( - users - .Select(u => new UserData(u)) - .ToList() - ); + return await IdentityUserIntegrationService.SearchAsync(input); } public virtual async Task GetCountAsync(UserLookupCountInputDto input) { - return await UserLookupServiceProvider.GetCountAsync(input.Filter); + return await IdentityUserIntegrationService.GetCountAsync(input); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs index b18f58f3a5..37446ce1f3 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs @@ -1,19 +1,69 @@ using System; +using System.Linq; using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Users; namespace Volo.Abp.Identity.Integration; public class IdentityUserIntegrationService : IdentityAppServiceBase, IIdentityUserIntegrationService { protected IUserRoleFinder UserRoleFinder { get; } + protected IdentityUserRepositoryExternalUserLookupServiceProvider UserLookupServiceProvider { get; } - public IdentityUserIntegrationService(IUserRoleFinder userRoleFinder) + public IdentityUserIntegrationService( + IUserRoleFinder userRoleFinder, + IdentityUserRepositoryExternalUserLookupServiceProvider userLookupServiceProvider) { UserRoleFinder = userRoleFinder; + UserLookupServiceProvider = userLookupServiceProvider; } public virtual async Task GetRoleNamesAsync(Guid id) { return await UserRoleFinder.GetRoleNamesAsync(id); } + + public virtual async Task FindByIdAsync(Guid id) + { + var userData = await UserLookupServiceProvider.FindByIdAsync(id); + if (userData == null) + { + return null; + } + + return new UserData(userData); + } + + public virtual async Task FindByUserNameAsync(string userName) + { + var userData = await UserLookupServiceProvider.FindByUserNameAsync(userName); + if (userData == null) + { + return null; + } + + return new UserData(userData); + } + + public virtual async Task> SearchAsync(UserLookupSearchInputDto input) + { + var users = await UserLookupServiceProvider.SearchAsync( + input.Sorting, + input.Filter, + input.MaxResultCount, + input.SkipCount + ); + + return new ListResultDto( + users + .Select(u => new UserData(u)) + .ToList() + ); + } + + public virtual async Task GetCountAsync(UserLookupCountInputDto input) + { + return await UserLookupServiceProvider.GetCountAsync(input.Filter); + } } From 56955627b27707686b5ee041ca0bbdb980eae717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 26 Sep 2023 10:36:19 +0300 Subject: [PATCH 2/4] Implemented controller and revised HttpClientExternalUserLookupServiceProvider --- ...ClientExternalUserLookupServiceProvider.cs | 15 +++++----- .../IdentityUserIntegrationController.cs | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientExternalUserLookupServiceProvider.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientExternalUserLookupServiceProvider.cs index 1c824db402..d73e09748d 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientExternalUserLookupServiceProvider.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientExternalUserLookupServiceProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity.Integration; using Volo.Abp.Users; namespace Volo.Abp.Identity; @@ -11,21 +12,21 @@ namespace Volo.Abp.Identity; [Dependency(TryRegister = true)] public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency { - protected IIdentityUserLookupAppService UserLookupAppService { get; } + protected IIdentityUserIntegrationService IdentityUserIntegrationService { get; } - public HttpClientExternalUserLookupServiceProvider(IIdentityUserLookupAppService userLookupAppService) + public HttpClientExternalUserLookupServiceProvider(IIdentityUserIntegrationService identityUserIntegrationService) { - UserLookupAppService = userLookupAppService; + IdentityUserIntegrationService = identityUserIntegrationService; } public virtual async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await UserLookupAppService.FindByIdAsync(id); + return await IdentityUserIntegrationService.FindByIdAsync(id); } public virtual async Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) { - return await UserLookupAppService.FindByUserNameAsync(userName); + return await IdentityUserIntegrationService.FindByUserNameAsync(userName); } public async Task> SearchAsync( @@ -35,7 +36,7 @@ public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupSe int skipCount = 0, CancellationToken cancellationToken = default) { - var result = await UserLookupAppService.SearchAsync( + var result = await IdentityUserIntegrationService.SearchAsync( new UserLookupSearchInputDto { Filter = filter, @@ -52,7 +53,7 @@ public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupSe string filter = null, CancellationToken cancellationToken = new CancellationToken()) { - return await UserLookupAppService + return await IdentityUserIntegrationService .GetCountAsync( new UserLookupCountInputDto { diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs index 3cb180e62b..e78691b1ac 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs @@ -1,7 +1,9 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Users; namespace Volo.Abp.Identity.Integration; @@ -24,4 +26,32 @@ public class IdentityUserIntegrationController : AbpControllerBase, IIdentityUse { return UserIntegrationService.GetRoleNamesAsync(id); } + + [HttpGet] + [Route("{id}")] + public Task FindByIdAsync(Guid id) + { + return UserIntegrationService.FindByIdAsync(id); + } + + [HttpGet] + [Route("by-username/{userName}")] + public Task FindByUserNameAsync(string userName) + { + return UserIntegrationService.FindByUserNameAsync(userName); + } + + [HttpGet] + [Route("search")] + public Task> SearchAsync(UserLookupSearchInputDto input) + { + return UserIntegrationService.SearchAsync(input); + } + + [HttpGet] + [Route("count")] + public Task GetCountAsync(UserLookupCountInputDto input) + { + return UserIntegrationService.GetCountAsync(input); + } } \ No newline at end of file From 7a29bb434899641ade1aec4fe45daeec75b73632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 26 Sep 2023 10:39:41 +0300 Subject: [PATCH 3/4] Regenerate client proxies --- .../Identity/IdentityUserLookupAppService.cs | 1 + ...ityUserIntegrationClientProxy.Generated.cs | 34 +++ .../identity-generate-proxy.json | 252 ++++++++++++++++++ 3 files changed, 287 insertions(+) diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs index d8baff07ad..297032c7a9 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs @@ -7,6 +7,7 @@ using Volo.Abp.Users; namespace Volo.Abp.Identity; +[Obsolete("Use IIdentityUserIntegrationService for module-to-module (or service-to-service) communication.")] [Authorize(IdentityPermissions.UserLookup.Default)] public class IdentityUserLookupAppService : IdentityAppServiceBase, IIdentityUserLookupAppService { diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/Integration/IdentityUserIntegrationClientProxy.Generated.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/Integration/IdentityUserIntegrationClientProxy.Generated.cs index cc6ab0f7a9..1c2f1b61cb 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/Integration/IdentityUserIntegrationClientProxy.Generated.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/Volo/Abp/Identity/Integration/IdentityUserIntegrationClientProxy.Generated.cs @@ -8,7 +8,9 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Http.Client; using Volo.Abp.Http.Client.ClientProxying; using Volo.Abp.Http.Modeling; +using Volo.Abp.Identity; using Volo.Abp.Identity.Integration; +using Volo.Abp.Users; // ReSharper disable once CheckNamespace namespace Volo.Abp.Identity.Integration; @@ -25,4 +27,36 @@ public partial class IdentityUserIntegrationClientProxy : ClientProxyBase FindByIdAsync(Guid id) + { + return await RequestAsync(nameof(FindByIdAsync), new ClientProxyRequestTypeValue + { + { typeof(Guid), id } + }); + } + + public virtual async Task FindByUserNameAsync(string userName) + { + return await RequestAsync(nameof(FindByUserNameAsync), new ClientProxyRequestTypeValue + { + { typeof(string), userName } + }); + } + + public virtual async Task> SearchAsync(UserLookupSearchInputDto input) + { + return await RequestAsync>(nameof(SearchAsync), new ClientProxyRequestTypeValue + { + { typeof(UserLookupSearchInputDto), input } + }); + } + + public virtual async Task GetCountAsync(UserLookupCountInputDto input) + { + return await RequestAsync(nameof(GetCountAsync), new ClientProxyRequestTypeValue + { + { typeof(UserLookupCountInputDto), input } + }); + } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json index ce96b88ee9..33efd0a6e7 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/ClientProxies/identity-generate-proxy.json @@ -1296,6 +1296,74 @@ "type": "System.String[]", "typeSimple": "[string]" } + }, + { + "name": "FindByIdAsync", + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "returnValue": { + "type": "Volo.Abp.Users.UserData", + "typeSimple": "Volo.Abp.Users.UserData" + } + }, + { + "name": "FindByUserNameAsync", + "parametersOnMethod": [ + { + "name": "userName", + "typeAsString": "System.String, System.Private.CoreLib", + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "returnValue": { + "type": "Volo.Abp.Users.UserData", + "typeSimple": "Volo.Abp.Users.UserData" + } + }, + { + "name": "SearchAsync", + "parametersOnMethod": [ + { + "name": "input", + "typeAsString": "Volo.Abp.Identity.UserLookupSearchInputDto, Volo.Abp.Identity.Application.Contracts", + "type": "Volo.Abp.Identity.UserLookupSearchInputDto", + "typeSimple": "Volo.Abp.Identity.UserLookupSearchInputDto", + "isOptional": false, + "defaultValue": null + } + ], + "returnValue": { + "type": "Volo.Abp.Application.Dtos.ListResultDto", + "typeSimple": "Volo.Abp.Application.Dtos.ListResultDto" + } + }, + { + "name": "GetCountAsync", + "parametersOnMethod": [ + { + "name": "input", + "typeAsString": "Volo.Abp.Identity.UserLookupCountInputDto, Volo.Abp.Identity.Application.Contracts", + "type": "Volo.Abp.Identity.UserLookupCountInputDto", + "typeSimple": "Volo.Abp.Identity.UserLookupCountInputDto", + "isOptional": false, + "defaultValue": null + } + ], + "returnValue": { + "type": "System.Int64", + "typeSimple": "number" + } } ] } @@ -1337,6 +1405,190 @@ }, "allowAnonymous": null, "implementFrom": "Volo.Abp.Identity.Integration.IIdentityUserIntegrationService" + }, + "FindByIdAsyncById": { + "uniqueName": "FindByIdAsyncById", + "name": "FindByIdAsync", + "httpMethod": "GET", + "url": "integration-api/identity/users/{id}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "id", + "name": "id", + "jsonName": null, + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "Volo.Abp.Users.UserData", + "typeSimple": "Volo.Abp.Users.UserData" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.Identity.Integration.IIdentityUserIntegrationService" + }, + "FindByUserNameAsyncByUserName": { + "uniqueName": "FindByUserNameAsyncByUserName", + "name": "FindByUserNameAsync", + "httpMethod": "GET", + "url": "integration-api/identity/users/by-username/{userName}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "userName", + "typeAsString": "System.String, System.Private.CoreLib", + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "userName", + "name": "userName", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "Volo.Abp.Users.UserData", + "typeSimple": "Volo.Abp.Users.UserData" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.Identity.Integration.IIdentityUserIntegrationService" + }, + "SearchAsyncByInput": { + "uniqueName": "SearchAsyncByInput", + "name": "SearchAsync", + "httpMethod": "GET", + "url": "integration-api/identity/users/search", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "input", + "typeAsString": "Volo.Abp.Identity.UserLookupSearchInputDto, Volo.Abp.Identity.Application.Contracts", + "type": "Volo.Abp.Identity.UserLookupSearchInputDto", + "typeSimple": "Volo.Abp.Identity.UserLookupSearchInputDto", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "input", + "name": "Filter", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + }, + { + "nameOnMethod": "input", + "name": "Sorting", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + }, + { + "nameOnMethod": "input", + "name": "SkipCount", + "jsonName": null, + "type": "System.Int32", + "typeSimple": "number", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + }, + { + "nameOnMethod": "input", + "name": "MaxResultCount", + "jsonName": null, + "type": "System.Int32", + "typeSimple": "number", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + } + ], + "returnValue": { + "type": "Volo.Abp.Application.Dtos.ListResultDto", + "typeSimple": "Volo.Abp.Application.Dtos.ListResultDto" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.Identity.Integration.IIdentityUserIntegrationService" + }, + "GetCountAsyncByInput": { + "uniqueName": "GetCountAsyncByInput", + "name": "GetCountAsync", + "httpMethod": "GET", + "url": "integration-api/identity/users/count", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "input", + "typeAsString": "Volo.Abp.Identity.UserLookupCountInputDto, Volo.Abp.Identity.Application.Contracts", + "type": "Volo.Abp.Identity.UserLookupCountInputDto", + "typeSimple": "Volo.Abp.Identity.UserLookupCountInputDto", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "input", + "name": "Filter", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + } + ], + "returnValue": { + "type": "System.Int64", + "typeSimple": "number" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.Identity.Integration.IIdentityUserIntegrationService" } } } From ced61b41d02f6b79676b548eb8d22ed8250c72c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 26 Sep 2023 13:35:23 +0300 Subject: [PATCH 4/4] Revised tests for IdentityUserIntegrationService --- .../Identity/IIdentityUserLookupAppService.cs | 1 + .../Identity/IdentityUserLookupAppService.cs | 2 +- .../IdentityUserIntegrationService_Tests.cs} | 36 ++++++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) rename modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/{IdentityUserLookupAppService_Tests.cs => Integration/IdentityUserIntegrationService_Tests.cs} (56%) diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs index 7a14579af5..d7ae1a5291 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs +++ b/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 FindByIdAsync(Guid id); diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs index 297032c7a9..7595de7a23 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs +++ b/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 { diff --git a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserLookupAppService_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/Integration/IdentityUserIntegrationService_Tests.cs similarity index 56% rename from modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserLookupAppService_Tests.cs rename to modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/Integration/IdentityUserIntegrationService_Tests.cs index e774b0e440..a74b5cdcfc 100644 --- a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserLookupAppService_Tests.cs +++ b/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(); + _identityUserIntegrationService = GetRequiredService(); _identityUserRepository = GetRequiredService(); _lookupNormalizer = GetRequiredService(); } + + [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"