Ejemplo n.º 1
0
        public void FindIdentityResourcesByScopeAsync_WhenResourcesExist_ExpectOnlyRequestedReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var resource = CreateIdentityTestResource();

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                context.IdentityResources.Add(resource.ToEntity());
                context.IdentityResources.Add(CreateIdentityTestResource().ToEntity());
                context.SaveChanges();
            }

            IList <IdentityResource> resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create());
                resources = store.FindIdentityResourcesByScopeAsync(new List <string>
                {
                    resource.Name
                }).Result.ToList();
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Equal(1, resources.Count);
        }
        public async Task FindIdentityResourcesByScopeAsync_WhenResourcesExist_ExpectOnlyRequestedReturned(ISessionFactory sessionFactory)
        {
            var resource = CreateIdentityTestResource();

            using (var provider = new ConfigurationSessionProvider(sessionFactory.OpenSession))
            {
                await provider.Session.SaveAsync(_mapper.Map <Entities.IdentityResource>(resource));

                await provider.Session.SaveAsync(_mapper.Map <Entities.IdentityResource>(CreateIdentityTestResource()));
            }

            IEnumerable <IdentityResource> resources;

            using (var provider = new ConfigurationSessionProvider(sessionFactory.OpenSession))
            {
                var store = new ResourceStore(provider);
                resources = await store.FindIdentityResourcesByScopeAsync(new List <string>
                {
                    resource.Name
                });
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Single(resources);
        }
Ejemplo n.º 3
0
        public void FindIdentityResourcesByScopeAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var resource = CreateIdentityTestResource();

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                context.IdentityResources.Add(resource.ToEntity());
                context.SaveChanges();
            }

            IList <IdentityResource> resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create());
                resources = store.FindIdentityResourcesByScopeAsync(new List <string>
                {
                    resource.Name
                }).Result.ToList();
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            var foundScope = resources.Single();

            Assert.Equal(resource.Name, foundScope.Name);
            Assert.NotNull(foundScope.UserClaims);
            Assert.NotEmpty(foundScope.UserClaims);
        }
        public async Task FindIdentityResourcesByScopeAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(ISessionFactory sessionFactory)
        {
            var resource = CreateIdentityTestResource();

            using (var provider = new ConfigurationSessionProvider(sessionFactory.OpenSession))
            {
                await provider.Session.SaveAsync(_mapper.Map <Entities.IdentityResource>(resource));
            }

            IEnumerable <IdentityResource> resources;

            using (var provider = new ConfigurationSessionProvider(sessionFactory.OpenSession))
            {
                var store = new ResourceStore(provider);
                resources = await store.FindIdentityResourcesByScopeAsync(new List <string>
                {
                    resource.Name
                });
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            var foundScope = resources.Single();

            Assert.Equal(resource.Name, foundScope.Name);
            Assert.NotNull(foundScope.UserClaims);
            Assert.NotEmpty(foundScope.UserClaims);
        }
        public async Task FindIdentityResourcesByScopeAsync_WhenResourcesExist_ExpectOnlyRequestedReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var resource = CreateIdentityTestResource();

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                context.IdentityResources.Add(resource.ToEntity());
                context.IdentityResources.Add(CreateIdentityTestResource().ToEntity());
                await context.SaveChangesAsync();
            }

            IEnumerable <IdentityResource> resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create());
                resources = await store.FindIdentityResourcesByScopeAsync(new List <string>
                {
                    resource.Name
                });
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Single(resources);
        }
        public async Task FindIdentityResourcesByScopeAsync_WhenScopeReceived_ExpectIdentityResourceWithSameNameReturned()
        {
            var store         = CreateIdentityResourceStore();
            var resourceStore = new ResourceStore(store, null);

            await store.StoreAsync(new IdentityResources.OpenId());

            await store.StoreAsync(new IdentityResources.Profile());

            var found = await resourceStore.FindIdentityResourcesByScopeAsync(new[] { "profile" });

            Assert.Single(found);
            Assert.Equal(new IdentityResources.Profile().Name, found.ToArray()[0].Name);
            Assert.Equal(new IdentityResources.Profile().DisplayName, found.ToArray()[0].DisplayName);
            Assert.Equal(new IdentityResources.Profile().Description, found.ToArray()[0].Description);
            Assert.Equal(new IdentityResources.Profile().ShowInDiscoveryDocument, found.ToArray()[0].ShowInDiscoveryDocument);
        }
Ejemplo n.º 7
0
        public void FindIdentityResourcesByScopeAsync_ShouldFindByScopes()
        {
            A.Configure <IdentityResource>().Fill(x => x.UserClaims, A.ListOf <IdentityClaim>(3));
            var resources = A.ListOf <IdentityResource>();

            using (var session = db.Store.LightweightSession())
            {
                session.StoreObjects(resources);
                session.SaveChanges();
            }
            using (var session = db.Store.LightweightSession())
            {
                var store  = new ResourceStore(session);
                var scopes = resources.Select(x => x.Name);
                var result = store.FindIdentityResourcesByScopeAsync(scopes).Result;
                Assert.True(resources.Count == result.Count());
            }
        }
        public async Task ResourceStore_Identity_SaveGetTest()
        {
            Stopwatch stopwatch = new Stopwatch();

            var storageContext = Services.BuildServiceProvider().GetService <ResourceStorageContext>();

            Assert.IsNotNull(storageContext);

            var store = new ResourceStore(storageContext, _logger);

            Assert.IsNotNull(store);

            foreach (Model.IdentityResource resource in GetIdentityResources())
            {
                Console.WriteLine(JsonConvert.SerializeObject(resource));

                stopwatch.Start();
                await store.StoreAsync(resource);

                stopwatch.Stop();
                Console.WriteLine($"ResourceStore.StoreAsync({resource.Name})-identity: {stopwatch.ElapsedMilliseconds} ms");

                stopwatch.Reset();
                stopwatch.Start();

                string[] findScopes          = new string[] { resource.Name, Guid.NewGuid().ToString() };
                var      findScopesResources = await store.FindIdentityResourcesByScopeAsync(findScopes);

                stopwatch.Stop();
                Console.WriteLine($"ResourceStore.FindIdentityResourcesByScopeAsync({resource.Name})-identity: {stopwatch.ElapsedMilliseconds} ms");
                Assert.AreEqual <string>(resource.Name, findScopesResources.Single()?.Name);
            }
            stopwatch.Reset();
            stopwatch.Start();
            var resources = await store.GetAllResourcesAsync();

            int count = resources.IdentityResources.Count();

            stopwatch.Stop();
            Console.WriteLine($"ResourceStore.GetAllResourcesAsync().IdentityResources.Count: {count} : {stopwatch.ElapsedMilliseconds} ms");
            Assert.AreEqual <int>(GetIdentityResources().Count(), count);
        }