Add PersistentGrantRepository tests.

pull/994/head
maliming 7 years ago
parent b8ae3ffefd
commit 1b8bd9fa36

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.IdentityServer
{
public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests<AbpIdentityServerTestEntityFrameworkCoreModule>
{
}
}

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.IdentityServer
{
public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests<AbpIdentityServerMongoDbTestModule>
{
}
}

@ -17,7 +17,7 @@ namespace Volo.Abp.IdentityServer
private readonly IClientRepository _clientRepository; private readonly IClientRepository _clientRepository;
private readonly IIdentityResourceRepository _identityResourceRepository; private readonly IIdentityResourceRepository _identityResourceRepository;
private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository;
//private readonly IPersistentGrantRepository _persistentGrantRepository; private readonly IPersistentGrantRepository _persistentGrantRepository;
private readonly AbpIdentityServerTestData _testData; private readonly AbpIdentityServerTestData _testData;
public AbpIdentityServerTestDataBuilder( public AbpIdentityServerTestDataBuilder(
@ -26,8 +26,8 @@ namespace Volo.Abp.IdentityServer
IClientRepository clientRepository, IClientRepository clientRepository,
IIdentityResourceRepository identityResourceRepository, IIdentityResourceRepository identityResourceRepository,
IIdentityClaimTypeRepository identityClaimTypeRepository, IIdentityClaimTypeRepository identityClaimTypeRepository,
AbpIdentityServerTestData testData AbpIdentityServerTestData testData,
/*IPersistentGrantRepository persistentGrantRepository*/) IPersistentGrantRepository persistentGrantRepository)
{ {
_testData = testData; _testData = testData;
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
@ -35,7 +35,7 @@ namespace Volo.Abp.IdentityServer
_clientRepository = clientRepository; _clientRepository = clientRepository;
_identityResourceRepository = identityResourceRepository; _identityResourceRepository = identityResourceRepository;
_identityClaimTypeRepository = identityClaimTypeRepository; _identityClaimTypeRepository = identityClaimTypeRepository;
//_persistentGrantRepository = persistentGrantRepository; _persistentGrantRepository = persistentGrantRepository;
} }
public void Build() public void Build()
@ -49,9 +49,25 @@ namespace Volo.Abp.IdentityServer
private void AddPersistedGrants() 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() private void AddIdentityResources()

@ -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<TStartupModule> : AbpIdentityServerTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IPersistentGrantRepository _persistentGrantRepository;
protected PersistentGrantRepository_Tests()
{
_persistentGrantRepository = GetRequiredService<IPersistentGrantRepository>();
}
[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");
}
}
}
Loading…
Cancel
Save