public async Task FindResourcesAsync_WhenResourcesExist_ExpectResourcesReturned(ISessionFactory sessionFactory)
        {
            var testIdentityResource = CreateIdentityTestResource();
            var testApiResource      = CreateApiTestResource();

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

                await provider.Session.SaveAsync(_mapper.Map <Entities.ApiResource>(testApiResource));
            }

            Resources resources;

            using (var provider = new ConfigurationSessionProvider(sessionFactory.OpenSession))
            {
                var store = new ResourceStore(provider);
                resources = await store.FindResourcesByScopeAsync(new List <string>
                {
                    testIdentityResource.Name,
                    testApiResource.Scopes.First().Name
                });
            }

            Assert.NotNull(resources);
            Assert.NotNull(resources.IdentityResources);
            Assert.NotEmpty(resources.IdentityResources);
            Assert.NotNull(resources.ApiResources);
            Assert.NotEmpty(resources.ApiResources);
            Assert.NotNull(resources.IdentityResources.FirstOrDefault(x => x.Name == testIdentityResource.Name));
            Assert.NotNull(resources.ApiResources.FirstOrDefault(x => x.Name == testApiResource.Name));
        }
Ejemplo n.º 2
0
        public void FindResourcesAsync_WhenResourcesExist_ExpectResourcesReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var testIdentityResource = CreateIdentityTestResource();
            var testApiResource      = CreateApiTestResource();

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

            Resources resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create());
                resources = store.FindResourcesByScopeAsync(new List <string>
                {
                    testIdentityResource.Name,
                    testApiResource.Scopes.First().Name
                }).Result;
            }

            Assert.NotNull(resources);
            Assert.NotNull(resources.IdentityResources);
            Assert.NotEmpty(resources.IdentityResources);
            Assert.NotNull(resources.ApiResources);
            Assert.NotEmpty(resources.ApiResources);
            Assert.NotNull(resources.IdentityResources.FirstOrDefault(x => x.Name == testIdentityResource.Name));
            Assert.NotNull(resources.ApiResources.FirstOrDefault(x => x.Name == testApiResource.Name));
        }
        public async Task FindResourcesAsync_WhenResourcesExist_ExpectOnlyResourcesRequestedReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var testIdentityResource = CreateIdentityTestResource();
            var testApiResource      = CreateApiTestResource();

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

            Resources resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create());
                resources = await store.FindResourcesByScopeAsync(new List <string>
                {
                    testIdentityResource.Name,
                    testApiResource.Scopes.First().Name
                });
            }

            Assert.NotNull(resources);
            Assert.NotNull(resources.IdentityResources);
            Assert.NotEmpty(resources.IdentityResources);
            Assert.NotNull(resources.ApiResources);
            Assert.NotEmpty(resources.ApiResources);
            Assert.Equal(1, resources.IdentityResources.Count);
            Assert.Equal(1, resources.ApiResources.Count);
        }