Added new test : StoreAsync_Should_Store_PersistedGrant

pull/190/head
Alper Ebicoglu 8 years ago
parent 127ac4f617
commit d2ff43dc6e

@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer.Clients
.ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets));
CreateMap<PersistedGrant, IdentityServer4.Models.PersistedGrant>();
CreateMap<PersistedGrant, IdentityServer4.Models.PersistedGrant>().ReverseMap();
CreateMap<IdentityResource, IdentityServer4.Models.IdentityResource>();

@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer.Grants
public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant)
{
var entity = _objectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant);
var existing = _persistentGrantRepository.FindByKeyAsync(grant.Key);
var existing = await _persistentGrantRepository.FindByKeyAsync(grant.Key);
if (existing == null)
{
await _persistentGrantRepository.InsertAsync(entity);

@ -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);
});
}
}
}

@ -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<IResourceStore>();
}
//too:WRITE TESTS
}
}

@ -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();
}
}
}

Loading…
Cancel
Save