示例#1
0
        public void GetAllResources_ShouldReturnAllResources()
        {
            var claims = A.ListOf <ApiResourceClaim>(2);
            var scopes = A.ListOf <ApiScope>();

            A.Configure <ApiResource>().Fill(x => x.UserClaims, claims);
            A.Configure <ApiResource>().Fill(x => x.Scopes, scopes);
            A.Configure <IdentityResource>().Fill(x => x.UserClaims, A.ListOf <IdentityClaim>(3));
            var resources    = A.ListOf <IdentityResource>(5);
            var apiResources = A.ListOf <ApiResource>(5);


            using (var session = db.Store.LightweightSession())
            {
                session.StoreObjects(resources);
                session.StoreObjects(apiResources);
                session.SaveChanges();
            }
            using (var session = db.Store.LightweightSession())
            {
                var store  = new ResourceStore(session);
                var result = store.GetAllResources().Result;

                Assert.True(apiResources.Count <= result.ApiResources.Count);
                Assert.True(resources.Count <= result.IdentityResources.Count);
            }
        }
示例#2
0
        public void GetAllResources_WhenAllResourcesRequested_ExpectAllResourcesIncludingHidden(DbContextOptions <ConfigurationDbContext> options)
        {
            var visibleIdentityResource = CreateIdentityTestResource();
            var visibleApiResource      = CreateApiTestResource();
            var hiddenIdentityResource  = new IdentityResource {
                Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false
            };
            var hiddenApiResource = new ApiResource
            {
                Name   = Guid.NewGuid().ToString(),
                Scopes = new List <Scope> {
                    new Scope {
                        Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false
                    }
                }
            };

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                context.IdentityResources.Add(visibleIdentityResource.ToEntity());
                context.ApiResources.Add(visibleApiResource.ToEntity());
                context.IdentityResources.Add(hiddenIdentityResource.ToEntity());
                context.ApiResources.Add(hiddenApiResource.ToEntity());
                context.SaveChanges();
            }

            Resources resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, NullLogger <ResourceStore> .Create());
                resources = store.GetAllResources().Result;
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources.IdentityResources);
            Assert.NotEmpty(resources.ApiResources);

            Assert.True(resources.IdentityResources.Any(x => !x.ShowInDiscoveryDocument));
            Assert.True(resources.ApiResources.Any(x => !x.Scopes.Any(y => y.ShowInDiscoveryDocument)));
        }