diff --git a/src/Stores/ResourceStore.cs b/src/Stores/ResourceStore.cs index d6c753b..d78f609 100644 --- a/src/Stores/ResourceStore.cs +++ b/src/Stores/ResourceStore.cs @@ -133,7 +133,9 @@ where scopes.Contains(identityResource.Name) public Task GetAllResourcesAsync() { var identity = _context.IdentityResources - .Include(x => x.UserClaims); + .Include(x => x.UserClaims) + .Include(x => x.Properties) + .AsNoTracking(); var apis = _context.ApiResources .Include(x => x.Secrets) diff --git a/test/IntegrationTests/Stores/ResourceStoreTests.cs b/test/IntegrationTests/Stores/ResourceStoreTests.cs index 9246c2a..87a791e 100644 --- a/test/IntegrationTests/Stores/ResourceStoreTests.cs +++ b/test/IntegrationTests/Stores/ResourceStoreTests.cs @@ -36,10 +36,15 @@ private static IdentityResource CreateIdentityTestResource() DisplayName = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = true, - UserClaims = + UserClaims = { JwtClaimTypes.Subject, JwtClaimTypes.Name, + }, + Properties = new Dictionary + { + { "key1", "value1"}, + { "key2", "value2"} } }; } @@ -49,7 +54,7 @@ private static ApiResource CreateApiTestResource() return new ApiResource() { Name = Guid.NewGuid().ToString(), - ApiSecrets = new List {new Secret("secret".ToSha256())}, + ApiSecrets = new List { new Secret("secret".ToSha256()) }, Scopes = new List { @@ -59,7 +64,7 @@ private static ApiResource CreateApiTestResource() UserClaims = {Guid.NewGuid().ToString()} } }, - UserClaims = + UserClaims = { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), @@ -139,11 +144,11 @@ public void GetAllResources_WhenAllResourcesRequested_ExpectAllResourcesIncludin { var visibleIdentityResource = CreateIdentityTestResource(); var visibleApiResource = CreateApiTestResource(); - var hiddenIdentityResource = new IdentityResource{Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false}; + var hiddenIdentityResource = new IdentityResource { Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false }; var hiddenApiResource = new ApiResource { Name = Guid.NewGuid().ToString(), - Scopes = new List {new Scope {Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false}} + Scopes = new List { new Scope { Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false } } }; using (var context = new ConfigurationDbContext(options, StoreOptions)) @@ -271,7 +276,7 @@ public void FindApiResourcesByScopeAsync_WhenResourceExists_ExpectResourceAndCol using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger.Create()); - resources = store.FindApiResourcesByScopeAsync(new List {resource.Scopes.First().Name}).Result.ToList(); + resources = store.FindApiResourcesByScopeAsync(new List { resource.Scopes.First().Name }).Result.ToList(); } Assert.NotEmpty(resources); @@ -303,12 +308,34 @@ public void FindApiResourcesByScopeAsync_WhenMultipleResourcesExist_ExpectOnlyRe using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger.Create()); - resources = store.FindApiResourcesByScopeAsync(new List {resource.Scopes.First().Name}).Result.ToList(); + resources = store.FindApiResourcesByScopeAsync(new List { resource.Scopes.First().Name }).Result.ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.Equal(1, resources.Count); } + + [Theory, MemberData(nameof(TestDatabaseProviders))] + public void GetAllResources_WhenIdentityResourceHasProperties_ExpectCollectionPopulated(DbContextOptions options) + { + var identityResourceWithProperties = CreateIdentityTestResource(); + using (var context = new ConfigurationDbContext(options, StoreOptions)) + { + context.IdentityResources.Add(identityResourceWithProperties.ToEntity()); + context.SaveChanges(); + } + + Resources resources; + using (var context = new ConfigurationDbContext(options, StoreOptions)) + { + var store = new ResourceStore(context, FakeLogger.Create()); + resources = store.GetAllResourcesAsync().Result; + } + + Assert.NotNull(resources); + Assert.NotEmpty(resources.IdentityResources); + Assert.Contains(resources.IdentityResources, x => x.Properties.Any()); + } } } \ No newline at end of file