public async Task FindApiScopesByNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var resource = CreateApiScopeTestResource();

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

            IList <ApiScope> resources;

            using (var context = new ConfigurationDbContext(options, StoreOptions))
            {
                var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create());
                resources = (await store.FindApiScopesByNameAsync(new List <string>
                {
                    resource.Name
                })).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 FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned(DbContextOptions <ConfigurationDbContext> options)
        {
            var resource = CreateApiScopeTestResource();

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

            IList <ApiScope> resources;

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

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.NotNull(resources.Single(x => x.Name == resource.Name));
        }
예제 #3
0
        public async Task FindApiScopesByNameAsync_should_find_apiScope_by_name()
        {
            using var store = new RavenDbTestDriverWrapper().GetDocumentStore();
            using var s1    = store.OpenAsyncSession();

            await s1.StoreAsync(new Entity.ApiScope
            {
                Id         = "test",
                Properties = new List <Entity.ApiScopeProperty>
                {
                    new Entity.ApiScopeProperty
                    {
                        Id = $"{nameof(Entity.ApiScopeProperty).ToLowerInvariant()}/test"
                    }
                }
            }, $"{nameof(Entity.ApiScope).ToLowerInvariant()}/test");

            await s1.StoreAsync(new Entity.ApiScopeProperty
            {
                Id         = "test",
                ApiScopeId = "test",
                Key        = "test",
                Value      = "test"
            }, $"{nameof(Entity.ApiScopeProperty).ToLowerInvariant()}/test");

            await s1.SaveChangesAsync();

            var sut = new ResourceStore(new ScopedAsynDocumentcSession(store.OpenAsyncSession()));

            var result = await sut.FindApiScopesByNameAsync(new[] { "test" });

            Assert.NotEmpty(result);
        }
예제 #4
0
        public async Task FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned()
        {
            using var ravenStore = GetDocumentStore();
            await new ApiScopeIndex().ExecuteAsync(ravenStore);
            var resource = CreateApiScopeTestResource();

            using (var session = ravenStore.OpenSession())
            {
                session.Store(resource.ToEntity());
                session.Store(CreateApiScopeTestResource().ToEntity());
                session.SaveChanges();
            }

            WaitForIndexing(ravenStore);

            IList <ApiScope> resources;

            using (var session = ravenStore.OpenAsyncSession())
            {
                var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create());
                resources = (await store.FindApiScopesByNameAsync(new List <string>
                {
                    resource.Name,
                    "non-existent"
                })).ToList();
            }

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.NotNull(resources.Single(x => x.Name == resource.Name));
        }
        public async Task FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned()
        {
            var storeHolder = GetConfigurationDocumentStoreHolder();

            var resource = CreateApiScopeTestResource();

            using (var session = storeHolder.OpenAsyncSession())
            {
                await session.StoreAsync(resource.ToEntity());

                await session.StoreAsync(CreateApiScopeTestResource().ToEntity());

                await session.SaveChangesAsync();
            }

            WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore());

            var store     = new ResourceStore(storeHolder, FakeLogger <ResourceStore> .Create());
            var resources = (await store.FindApiScopesByNameAsync(new List <string>
            {
                resource.Name,
                "non-existent"
            })).ToList();

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.NotNull(resources.Single(x => x.Name == resource.Name));
        }
예제 #6
0
        public async Task FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned()
        {
            var resource = CreateApiScopeTestResource();

            var entity = resource.ToEntity();

            var repo = g.configurationDb.GetRepository <Storage.Entities.ApiScope>();

            repo.Insert(entity);
            repo.SaveMany(entity, "UserClaims");
            repo.SaveMany(entity, "Properties");

            IList <ApiScope> resources;

            var store = new ResourceStore(g.configurationDb, FakeLogger <ResourceStore> .Create());

            resources = (await store.FindApiScopesByNameAsync(new List <string>
            {
                resource.Name
            })).ToList();

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.NotNull(resources.Single(x => x.Name == resource.Name));
        }
예제 #7
0
        public async Task ResourceStore_Api_SaveGetTest()
        {
            Stopwatch stopwatch = new Stopwatch();

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

            Assert.IsNotNull(storageContext);

            var store = new ResourceStore(storageContext, _logger);

            Assert.IsNotNull(store);

            var resource = CreateApiTestObject();

            Console.WriteLine(JsonConvert.SerializeObject(resource));

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

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

            stopwatch.Reset();
            stopwatch.Start();
            var findResource = (await store.FindApiResourcesByNameAsync(new string[] { resource.Name })).FirstOrDefault();

            stopwatch.Stop();
            Console.WriteLine($"{nameof(ResourceStore.FindApiResourcesByNameAsync)}({resource.Name})-api: {stopwatch.ElapsedMilliseconds} ms");
            Assert.AreEqual <string>(resource.Name, findResource.Name);

            stopwatch.Reset();
            stopwatch.Start();
            string[] findScopes          = new string[] { "api1Scope", Guid.NewGuid().ToString() };
            var      findScopesResources = await store.FindApiResourcesByScopeNameAsync(findScopes);

            stopwatch.Stop();
            Console.WriteLine($"ResourceStore.FindApiResourcesByScopeAsync({string.Join(",", findScopes)})-api: {stopwatch.ElapsedMilliseconds} ms");
            Assert.AreEqual <string>(resource.Name, findScopesResources.Single()?.Name);

            stopwatch.Reset();
            stopwatch.Start();
            var resources = await store.GetAllResourcesAsync();

            int count = resources.ApiResources.Count();

            stopwatch.Stop();
            Console.WriteLine($"ResourceStore.GetAllResourcesAsync().ApiResources.Count: {count} : {stopwatch.ElapsedMilliseconds} ms");
            Assert.IsTrue(count > 0);


            stopwatch.Reset();
            stopwatch.Start();
            string findScope = findScopes[0];
            var    apiScopes = await store.FindApiScopesByNameAsync(findScopes);

            stopwatch.Stop();
            Console.WriteLine($"ResourceStore.FindApiScopesByNameAsync({findScope})-api: {stopwatch.ElapsedMilliseconds} ms");
            Assert.AreEqual <int>(1, apiScopes.Where(w => w.Name == findScope).Count());
        }
예제 #8
0
    public async Task Can_call_ResourceStore_FindApiScopesByNameAsync()
    => await ExecuteWithStrategyInTransactionAsync(
        async context =>
    {
        await SaveApiScopes(context);
    },
        async context =>
    {
        var store = new ResourceStore(context, new FakeLogger <ResourceStore>());

        Assert.Equal(2, (await store.FindApiScopesByNameAsync(new[] { "ApiScope2", "ApiScope1" })).Count());
    }
        );
예제 #9
0
        public async Task FindApiScopesByNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned()
        {
            var resource = CreateApiScopeTestResource();

            await _context.ApiScopes.AddAsync(resource.ToEntity());

            await _context.ApiScopes.AddAsync(CreateApiScopeTestResource().ToEntity());

            IList <ApiScope> resources;
            var store = new ResourceStore(_context, FakeLogger <ResourceStore> .Create());

            resources = (await store.FindApiScopesByNameAsync(new List <string>
            {
                resource.Name
            })).ToList();

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.NotNull(resources.Single(x => x.Name == resource.Name));
        }
예제 #10
0
        public async Task ResourceStore_MigrateV3Test()
        {
            Stopwatch stopwatch = new Stopwatch();

            Services.AddScoped <IResourceStore, ResourceStore>();
            var storageContext = Services.BuildServiceProvider().GetService <ResourceStorageContext>();

            Assert.IsNotNull(storageContext);

            var store = new ResourceStore(storageContext, _logger);

            Assert.IsNotNull(store);

            string apiResourceName = "aipResourceName-" + Guid.NewGuid().ToString();

            Console.WriteLine($"api resource name: {apiResourceName}");
            string scopeName = "scopeName-" + Guid.NewGuid().ToString();

            Console.WriteLine($"api scope name: {scopeName}");

            var resource = CreateApiV3EntityTestObject(apiResourceName, scopeName);
            await storageContext.SaveBlobWithHashedKeyAsync(apiResourceName, JsonConvert.SerializeObject(resource),
                                                            storageContext.ApiResourceBlobContainer);

            // Run Migration
            stopwatch.Start();
            Services.MigrateResourceV3Storage();
            stopwatch.Stop();
            Console.WriteLine($"MigrateResourceV3Storage-api: {stopwatch.ElapsedMilliseconds} ms");

            stopwatch.Reset();
            stopwatch.Start();
            string[] findScopes    = new string[] { scopeName, Guid.NewGuid().ToString() };
            var      findApiScopes = await store.FindApiScopesByNameAsync(findScopes);

            stopwatch.Stop();
            Console.WriteLine($"ResourceStore.FindApiScopesByNameAsync({string.Join(",", findScopes)})-api: {stopwatch.ElapsedMilliseconds} ms");
            Assert.AreEqual <string>(scopeName, findApiScopes.Single()?.Name);
            Assert.IsTrue(findApiScopes.Single().UserClaims.AsEnumerable().Any(a => a == resource.Scopes.First().UserClaims.First().Type));
        }
예제 #11
0
        public async Task FindApiScopesByNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned()
        {
            var resource = CreateApiScopeTestResource();

            await _context.ApiScopes.AddAsync(resource.ToEntity());

            IList <ApiScope> resources;
            var store = new ResourceStore(_context, FakeLogger <ResourceStore> .Create());

            resources = (await store.FindApiScopesByNameAsync(new List <string>
            {
                resource.Name
            })).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);
        }