From 2527faaa37d6f95911b9e2762209514c3c38eac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 24 Dec 2019 17:05:14 +0300 Subject: [PATCH] identityserver remove old sync api usage --- .../AbpIdentityServerTestDataBuilder.cs | 37 +++++++------- ...tityServerTestEntityFrameworkCoreModule.cs | 5 +- .../AbpIdentityServerTestBaseModule.cs | 5 +- .../AbpIdentityServerTestDataBuilder.cs | 49 ++++++++++--------- 4 files changed, 50 insertions(+), 46 deletions(-) diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index 2eef9ffc57..0d87a2fd19 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -1,4 +1,5 @@ -using IdentityServer4.Models; +using System.Threading.Tasks; +using IdentityServer4.Models; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.IdentityServer.ApiResources; @@ -12,7 +13,7 @@ using PersistedGrant = Volo.Abp.IdentityServer.Grants.PersistedGrant; namespace Volo.Abp.IdentityServer { - //TODO: There are two data builders (ses AbpIdentityServerTestDataBuilder in Volo.Abp.IdentityServer.TestBase). It should be somehow unified! + //TODO: There are two data builders (see AbpIdentityServerTestDataBuilder in Volo.Abp.IdentityServer.TestBase). It should be somehow unified! public class AbpIdentityServerTestDataBuilder : ITransientDependency { @@ -36,15 +37,15 @@ namespace Volo.Abp.IdentityServer _identityResourceRepository = identityResourceRepository; } - public void Build() + public async Task BuildAsync() { - AddClients(); - AddPersistentGrants(); - AddApiResources(); - AddIdentityResources(); + await AddClients(); + await AddPersistentGrants(); + await AddApiResources(); + await AddIdentityResources(); } - private void AddClients() + private async Task AddClients() { var client42 = new Client(_guidGenerator.Create(), "42") { @@ -55,12 +56,12 @@ namespace Volo.Abp.IdentityServer client42.AddScope("api1"); - _clientRepository.Insert(client42); + await _clientRepository.InsertAsync(client42); } - private void AddPersistentGrants() + private async Task AddPersistentGrants() { - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "38", ClientId = "TestClientId-38", @@ -69,7 +70,7 @@ namespace Volo.Abp.IdentityServer Data = "TestData-38" }); - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "37", ClientId = "TestClientId-37", @@ -78,7 +79,7 @@ namespace Volo.Abp.IdentityServer Data = "TestData-37" }); - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "36", ClientId = "TestClientId-X", @@ -87,7 +88,7 @@ namespace Volo.Abp.IdentityServer Data = "TestData-36" }); - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "35", ClientId = "TestClientId-X", @@ -97,7 +98,7 @@ namespace Volo.Abp.IdentityServer }); } - private void AddApiResources() + private async Task AddApiResources() { var apiResource = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1") { @@ -110,10 +111,10 @@ namespace Volo.Abp.IdentityServer apiResource.AddScope("Test-ApiResource-ApiScope-Name-1", "Test-ApiResource-ApiScope-DisplayName-1"); apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1"); - _apiResourceRepository.Insert(apiResource); + await _apiResourceRepository.InsertAsync(apiResource); } - private void AddIdentityResources() + private async Task AddIdentityResources() { var identityResource = new IdentityResource(_guidGenerator.Create(), "Test-Identity-Resource-Name-1") { @@ -125,7 +126,7 @@ namespace Volo.Abp.IdentityServer identityResource.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1"); - _identityResourceRepository.Insert(identityResource); + await _identityResourceRepository.InsertAsync(identityResource); } } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs index 627ae45e38..450bd922f8 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs @@ -7,6 +7,7 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.Modularity; +using Volo.Abp.Threading; namespace Volo.Abp.IdentityServer { @@ -55,9 +56,9 @@ namespace Volo.Abp.IdentityServer { using (var scope = context.ServiceProvider.CreateScope()) { - scope.ServiceProvider + AsyncHelper.RunSync(() => scope.ServiceProvider .GetRequiredService() - .Build(); + .BuildAsync()); } } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs index b80cfedc20..29c748361a 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Autofac; using Volo.Abp.Modularity; +using Volo.Abp.Threading; namespace Volo.Abp.IdentityServer { @@ -25,9 +26,9 @@ namespace Volo.Abp.IdentityServer { using (var scope = context.ServiceProvider.CreateScope()) { - scope.ServiceProvider + AsyncHelper.RunSync(() => scope.ServiceProvider .GetRequiredService() - .Build(); + .BuildAsync()); } } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index f86d060d5b..dd0016e666 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.Identity; @@ -38,18 +39,18 @@ namespace Volo.Abp.IdentityServer _persistentGrantRepository = persistentGrantRepository; } - public void Build() + public async Task BuildAsync() { - AddPersistedGrants(); - AddIdentityResources(); - AddApiResources(); - AddClients(); - AddClaimTypes(); + await AddPersistedGrants(); + await AddIdentityResources(); + await AddApiResources(); + await AddClients(); + await AddClaimTypes(); } - private void AddPersistedGrants() + private async Task AddPersistedGrants() { - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "PersistedGrantKey1", SubjectId = "PersistedGrantSubjectId1", @@ -58,7 +59,7 @@ namespace Volo.Abp.IdentityServer Data = "" }); - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "PersistedGrantKey2", SubjectId = "PersistedGrantSubjectId2", @@ -67,7 +68,7 @@ namespace Volo.Abp.IdentityServer Data = "" }); - _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { Key = "PersistedGrantKey3", SubjectId = "PersistedGrantSubjectId3", @@ -77,7 +78,7 @@ namespace Volo.Abp.IdentityServer }); } - private void AddIdentityResources() + private async Task AddIdentityResources() { var identityResource = new IdentityResource(_testData.IdentityResource1Id, "NewIdentityResource1") { @@ -87,12 +88,12 @@ namespace Volo.Abp.IdentityServer identityResource.AddUserClaim(nameof(ApiResourceClaim.Type)); - _identityResourceRepository.Insert(identityResource); - _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); - _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); + await _identityResourceRepository.InsertAsync(identityResource); + await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); + await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); } - private void AddApiResources() + private async Task AddApiResources() { var apiResource = new ApiResource(_testData.ApiResource1Id, "NewApiResource1"); apiResource.Description = nameof(apiResource.Description); @@ -102,12 +103,12 @@ namespace Volo.Abp.IdentityServer apiResource.AddUserClaim(nameof(ApiResourceClaim.Type)); apiResource.AddSecret(nameof(ApiSecret.Value)); - _apiResourceRepository.Insert(apiResource); - _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); - _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); + await _apiResourceRepository.InsertAsync(apiResource); + await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); + await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); } - private void AddClients() + private async Task AddClients() { var client = new Client(_testData.Client1Id, "ClientId1") { @@ -129,17 +130,17 @@ namespace Volo.Abp.IdentityServer client.AddScope(nameof(ClientScope.Scope)); client.AddSecret(nameof(ClientSecret.Value)); - _clientRepository.Insert(client); + await _clientRepository.InsertAsync(client); - _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); - _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); + await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")); + await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")); } - private void AddClaimTypes() + private async Task AddClaimTypes() { var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null, IdentityClaimValueType.Int); - _identityClaimTypeRepository.Insert(ageClaim); + await _identityClaimTypeRepository.InsertAsync(ageClaim); } } }