From 487b4860c997e632f72c76a300c6f369b2d9d69b Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Fri, 5 Jan 2018 15:43:59 +0300 Subject: [PATCH] Added PersistedGrantStore --- .../AbpIdentityServerTestDataBuilder.cs | 21 +++++++++- .../Clients/PersistentGrant_Tests.cs | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs 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 6fc4153dc8..53d082bcc4 100644 --- a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -2,25 +2,30 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.IdentityServer.Clients; +using Volo.Abp.IdentityServer.Grants; namespace Volo.Abp.IdentityServer { public class AbpIdentityServerTestDataBuilder : ITransientDependency { private readonly IClientRepository _clientRepository; + private readonly IPersistentGrantRepository _persistentGrantRepository; private readonly IGuidGenerator _guidGenerator; public AbpIdentityServerTestDataBuilder( IClientRepository clientRepository, - IGuidGenerator guidGenerator) + IGuidGenerator guidGenerator, + IPersistentGrantRepository persistentGrantRepository) { _clientRepository = clientRepository; _guidGenerator = guidGenerator; + _persistentGrantRepository = persistentGrantRepository; } public void Build() { AddClients(); + AddPersistentGrants(); } private void AddClients() @@ -40,5 +45,19 @@ namespace Volo.Abp.IdentityServer _clientRepository.Insert(client42); } + + private void AddPersistentGrants() + { + var persistentGrant38 = 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/PersistentGrant_Tests.cs b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs new file mode 100644 index 0000000000..b59936fef2 --- /dev/null +++ b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; +using IdentityServer4.Stores; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Xunit; + +namespace Volo.Abp.IdentityServer.Clients +{ + public class PersistentGrantStore_Tests : AbpIdentityServerTestBase + { + private readonly IPersistedGrantStore _persistedGrantStore; + + public PersistentGrantStore_Tests() + { + _persistedGrantStore = ServiceProvider.GetRequiredService(); + } + + [Fact] + public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() + { + var persistentGrant = await _persistedGrantStore.GetAsync("not-existing-id"); + persistentGrant.ShouldBeNull(); + } + + [Fact] + public async Task FindPersistentGrantByIdAsync_Should_Return_The_PersistentGrant_If_Found() + { + //Act + var client = await _persistedGrantStore.GetAsync("38"); + + //Assert + client.ShouldNotBeNull(); + client.ClientId.ShouldBe("TestClientId-38"); + client.SubjectId.ShouldBe("TestSubject-38"); + client.Data.ShouldContain("TestData-38"); + client.Type.ShouldContain("TestType-38"); + } + } +}