public async Task FindClientByIdAsync_WhenClientIdReceived_ExpectClientToBeReturned()
        {
            var store = new ClientStore(StoreOptions, new FakeLogger <ClientStore>());

            foreach (var testObject in GetClientTestObjects())
            {
                await store.StoreAsync(testObject);
            }

            var client = await store.FindClientByIdAsync("roclient");

            Assert.Single(client.Claims);
            Assert.Equal("role", client.Claims.ToArray()[0].Type);
            Assert.Equal("service", client.Claims.ToArray()[0].Value);

            Assert.Equal("https://cors/", client.AllowedCorsOrigins.ToArray()[0]);
            Assert.Equal("https://origin/", client.AllowedCorsOrigins.ToArray()[1]);

            Assert.Single(client.AllowedGrantTypes);
            Assert.Equal("password", client.AllowedGrantTypes.ToArray()[0]);

            Assert.Single(client.ClientSecrets);
            Assert.Equal("K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=", client.ClientSecrets.ToArray()[0].Value);
            Assert.Equal("SharedSecret", client.ClientSecrets.ToArray()[0].Type);

            Assert.Equal("api1", client.AllowedScopes.ToArray()[0]);
            Assert.Equal("api2.read_only", client.AllowedScopes.ToArray()[1]);

            Assert.Equal("provider", client.IdentityProviderRestrictions.ToArray()[0]);

            Assert.Equal("https://logout/redirect/", client.PostLogoutRedirectUris.ToArray()[0]);
            Assert.Equal("https://logout/redirect-failure/", client.PostLogoutRedirectUris.ToArray()[1]);

            Assert.Equal("https://redirect/", client.RedirectUris.ToArray()[0]);
        }
        private static void Seed(IApplicationBuilder app)
        {
            var options = app.ApplicationServices.GetRequiredService <IOptions <TableStorageConfigurationOptions> >();

            // seed API resources

            var apiResourceLogger = app.ApplicationServices.GetRequiredService <ILogger <ApiResourceTableStore> >();
            var apiResourceStore  = new ApiResourceTableStore(options, apiResourceLogger);

            foreach (var apiResource in Host.Configuration.Resources.GetApiResources())
            {
                apiResourceStore.StoreAsync(apiResource).GetAwaiter().GetResult();
            }

            // seed Identity resources

            var identityResourceLogger = app.ApplicationServices.GetRequiredService <ILogger <IdentityResourceTableStore> >();
            var identityResourceStore  = new IdentityResourceTableStore(options, identityResourceLogger);

            foreach (var identityResource in Host.Configuration.Resources.GetIdentityResources())
            {
                identityResourceStore.StoreAsync(identityResource).GetAwaiter().GetResult();
            }

            // seed Clients

            var clientLogger = app.ApplicationServices.GetRequiredService <ILogger <ClientStore> >();
            var clientStore  = new ClientStore(options, clientLogger);

            foreach (var client in Clients.Get())
            {
                clientStore.StoreAsync(client).GetAwaiter().GetResult();
            }
        }
        public async Task ClientStore_SaveGetByClientIdTest()
        {
            Stopwatch stopwatch = new Stopwatch();

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

            Assert.IsNotNull(storageContext);

            var store = new ClientStore(storageContext, _logger);

            Assert.IsNotNull(store);

            var client = CreateTestObject();

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

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

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.StoreAsync({client.ClientId}): {stopwatch.ElapsedMilliseconds} ms");

            stopwatch.Reset();
            stopwatch.Start();
            var findClient = await store.FindClientByIdAsync(client.ClientId);

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.FindClientByIdAsync({client.ClientId}): {stopwatch.ElapsedMilliseconds} ms");
            Assert.AreEqual <string>(client.ClientId, findClient.ClientId);

            stopwatch.Reset();
            stopwatch.Start();
            var clients = await store.GetAllClients();

            int count = clients.Count();

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

            stopwatch.Reset();
            stopwatch.Start();
            var getClient = (await store.GetAllClients()).FirstOrDefault(f => f.ClientId == client.ClientId);

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.GetAllClients(): {stopwatch.ElapsedMilliseconds} ms");
            Assert.IsNotNull(getClient);
        }
        public async Task ClientStore_RemoveByClientIdTest()
        {
            var storageContext = Services.BuildServiceProvider().GetService <ClientStorageContext>();

            Assert.IsNotNull(storageContext);

            var store = new ClientStore(storageContext, _logger);

            Assert.IsNotNull(store);

            var client = CreateTestObject();

            client.ClientId = Guid.NewGuid().ToString();
            Console.WriteLine(JsonConvert.SerializeObject(client));

            Stopwatch stopwatch = new Stopwatch();

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

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.StoreAsync({client.ClientId}): {stopwatch.ElapsedMilliseconds} ms");
            stopwatch.Reset();

            stopwatch.Start();
            await store.RemoveAsync(client.ClientId);

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.RemoveAsync({client.ClientId}): {stopwatch.ElapsedMilliseconds} ms");

            stopwatch.Reset();
            stopwatch.Start();
            var findClient = await store.FindClientByIdAsync(client.ClientId);

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.FindClientByIdAsync({client.ClientId}): {stopwatch.ElapsedMilliseconds} ms");
            Assert.IsNull(findClient);

            stopwatch.Reset();
            stopwatch.Start();
            var getClient = (await store.GetAllClients()).FirstOrDefault(f => f.ClientId == client.ClientId);

            stopwatch.Stop();
            Console.WriteLine($"ClientStore.GetAllClients(): {stopwatch.ElapsedMilliseconds} ms");
            Assert.IsNull(getClient);
        }