diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs similarity index 100% rename from modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs rename to modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs similarity index 100% rename from modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs rename to modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs similarity index 100% rename from modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs rename to modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs new file mode 100644 index 0000000000..79bab1d23a --- /dev/null +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Volo.Abp.IdentityServer +{ + public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests + { + + } +} diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs new file mode 100644 index 0000000000..fd2763dc6c --- /dev/null +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Volo.Abp.IdentityServer +{ + public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests + { + + } +} 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 0c18e85350..016820af49 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,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; +using Volo.Abp.Identity; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.Grants; @@ -14,7 +16,8 @@ namespace Volo.Abp.IdentityServer private readonly IApiResourceRepository _apiResourceRepository; private readonly IClientRepository _clientRepository; private readonly IIdentityResourceRepository _identityResourceRepository; - //private readonly IPersistentGrantRepository _persistentGrantRepository; + private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; + private readonly IPersistentGrantRepository _persistentGrantRepository; private readonly AbpIdentityServerTestData _testData; public AbpIdentityServerTestDataBuilder( @@ -22,15 +25,17 @@ namespace Volo.Abp.IdentityServer IApiResourceRepository apiResourceRepository, IClientRepository clientRepository, IIdentityResourceRepository identityResourceRepository, - AbpIdentityServerTestData testData - /*IPersistentGrantRepository persistentGrantRepository*/) + IIdentityClaimTypeRepository identityClaimTypeRepository, + AbpIdentityServerTestData testData, + IPersistentGrantRepository persistentGrantRepository) { _testData = testData; _guidGenerator = guidGenerator; _apiResourceRepository = apiResourceRepository; _clientRepository = clientRepository; _identityResourceRepository = identityResourceRepository; - //_persistentGrantRepository = persistentGrantRepository; + _identityClaimTypeRepository = identityClaimTypeRepository; + _persistentGrantRepository = persistentGrantRepository; } public void Build() @@ -39,13 +44,30 @@ namespace Volo.Abp.IdentityServer AddIdentityResources(); AddApiResources(); AddClients(); + AddClaimTypes(); } private void AddPersistedGrants() { - //_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())); - //_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())); - //_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())); + _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + { + + Key = "PersistedGrantKey1", + SubjectId = "PersistedGrantSubjectId1", + ClientId = "PersistedGrantClientId1", + Type = "PersistedGrantType1" + }); + _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + { + Key = "PersistedGrantKey2", + SubjectId = "PersistedGrantSubjectId2" + }); + + _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) + { + Key = "PersistedGrantKey3", + SubjectId = "PersistedGrantSubjectId3" + }); } private void AddIdentityResources() @@ -105,5 +127,12 @@ namespace Volo.Abp.IdentityServer _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); } + + private void AddClaimTypes() + { + var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null, + IdentityClaimValueType.Int); + _identityClaimTypeRepository.Insert(ageClaim); + } } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs new file mode 100644 index 0000000000..20f6674515 --- /dev/null +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.IdentityServer.Grants; +using Volo.Abp.Modularity; +using Xunit; + +namespace Volo.Abp.IdentityServer +{ + public abstract class PersistentGrantRepository_Tests : AbpIdentityServerTestBase + where TStartupModule : IAbpModule + { + private readonly IPersistentGrantRepository _persistentGrantRepository; + + protected PersistentGrantRepository_Tests() + { + _persistentGrantRepository = GetRequiredService(); + } + + [Fact] + public async Task FindByKeyAsync() + { + (await _persistentGrantRepository.FindByKeyAsync("PersistedGrantKey1")).ShouldNotBeNull(); + } + + [Fact] + public async Task GetListBySubjectIdAsync() + { + var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync("PersistedGrantSubjectId1"); + persistedGrants.ShouldNotBeEmpty(); + persistedGrants.ShouldContain(x => x.Key == "PersistedGrantKey1"); + } + + [Fact] + public async Task DeleteBySubjectIdAndClientId() + { + await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1"); + + var persistedGrants = await _persistentGrantRepository.GetListAsync(); + persistedGrants.ShouldNotBeEmpty(); + persistedGrants.ShouldNotContain(x => + x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && + x.ClientId == "PersistedGrantClientId1"); + } + + [Fact] + public async Task DeleteBySubjectIdAndClientIdAndType() + { + await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1", + "PersistedGrantClientId1"); + + var persistedGrants = await _persistentGrantRepository.GetListAsync(); + persistedGrants.ShouldNotBeEmpty(); + persistedGrants.ShouldNotContain(x => + x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && + x.ClientId == "PersistedGrantClientId1" && x.Type == "PersistedGrantClientId1"); + + } + } +}