Esempio n. 1
0
        public async Task ResourceStore_Identity_RemoveGetTest()
        {
            Stopwatch stopwatch = new Stopwatch();

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

            Assert.IsNotNull(storageContext);

            var store = new ResourceStore(storageContext, _logger);

            Assert.IsNotNull(store);

            var resource = new IdentityResources.Address();

            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();
            var resources = await store.GetAllResourcesAsync();

            int count = resources.IdentityResources.Count();

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

            stopwatch.Reset();
            //Remove
            stopwatch.Start();

            await store.RemoveIdentityResourceAsync(resource.Name);

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

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

            stopwatch.Stop();
            Console.WriteLine($"ResourceStore.GetAllResourcesAsync().IdentityResources.Count: {count} : {stopwatch.ElapsedMilliseconds} ms");
            Assert.IsNull(resources.IdentityResources.FirstOrDefault(f => f.Name == resource.Name));
        }