diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientAutoMapperProfile.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientAutoMapperProfile.cs index 0280ed4bda..b76f22e5af 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientAutoMapperProfile.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientAutoMapperProfile.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer.Clients .ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets)); - CreateMap(); + CreateMap().ReverseMap(); CreateMap(); diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs index 409353167e..f312132900 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer.Grants public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) { var entity = _objectMapper.Map(grant); - var existing = _persistentGrantRepository.FindByKeyAsync(grant.Key); + var existing = await _persistentGrantRepository.FindByKeyAsync(grant.Key); if (existing == null) { await _persistentGrantRepository.InsertAsync(entity); diff --git a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index 53d082bcc4..f5936a7552 100644 --- a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -48,16 +48,14 @@ namespace Volo.Abp.IdentityServer private void AddPersistentGrants() { - var persistentGrant38 = new PersistedGrant(_guidGenerator.Create()) + _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) { Key = "38", ClientId = "TestClientId-38", Type = "TestType-38", SubjectId = "TestSubject-38", Data = "TestData-38" - }; - - _persistentGrantRepository.Insert(persistentGrant38); + }); } } } diff --git a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs new file mode 100644 index 0000000000..1c8c3fe310 --- /dev/null +++ b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; +using IdentityServer4.Stores; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Xunit; + +namespace Volo.Abp.IdentityServer.Clients +{ + public class IdentityResourceStore_Tests : AbpIdentityServerTestBase + { + private readonly IResourceStore _persistedGrantStore; + + public IdentityResourceStore_Tests() + { + _persistedGrantStore = ServiceProvider.GetRequiredService(); + } + + //too:WRITE TESTS + } +} diff --git a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs index b59936fef2..46b8f9af45 100644 --- a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs +++ b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +using IdentityServer4.Models; using IdentityServer4.Stores; using Microsoft.Extensions.DependencyInjection; using Shouldly; @@ -35,5 +37,52 @@ namespace Volo.Abp.IdentityServer.Clients client.Data.ShouldContain("TestData-38"); client.Type.ShouldContain("TestType-38"); } + + [Fact] + public async Task StoreAsync_Should_Store_PersistedGrant() + { + //Act + await _persistedGrantStore.StoreAsync(new PersistedGrant + { + Key = "39", + ClientId = "TestClientId-39", + Type = "TestType-39", + SubjectId = "TestSubject-39", + Data = "TestData-39", + Expiration = new DateTime(2018, 1, 6, 21, 22, 23), + CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) + }); + + //Assert + var persistedGrant = await _persistedGrantStore.GetAsync("39"); + persistedGrant.Key.ShouldBe("39"); + persistedGrant.ClientId.ShouldBe("TestClientId-39"); + persistedGrant.Type.ShouldBe("TestType-39"); + persistedGrant.SubjectId.ShouldBe("TestSubject-39"); + persistedGrant.Data.ShouldBe("TestData-39"); + + persistedGrant.Expiration.HasValue.ShouldBe(true); + persistedGrant.Expiration.Value.Year.ShouldBe(2018); + persistedGrant.Expiration.Value.Month.ShouldBe(1); + persistedGrant.Expiration.Value.Day.ShouldBe(6); + persistedGrant.Expiration.Value.Hour.ShouldBe(21); + persistedGrant.Expiration.Value.Minute.ShouldBe(22); + persistedGrant.Expiration.Value.Second.ShouldBe(23); + + persistedGrant.CreationTime.Year.ShouldBe(2018); + persistedGrant.CreationTime.Month.ShouldBe(1); + persistedGrant.CreationTime.Day.ShouldBe(5); + persistedGrant.CreationTime.Hour.ShouldBe(19); + persistedGrant.CreationTime.Minute.ShouldBe(20); + persistedGrant.CreationTime.Second.ShouldBe(21); + } + + [Fact] + public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() + { + var persistentGrant = await _persistedGrantStore.GetAllAsync("not-existing-id"); + persistentGrant.ShouldBeNull(); + } + } }