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()); }
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)); }
public async Task ResourceStore_Api_RemoveGetTest() { Stopwatch stopwatch = new Stopwatch(); var storageContext = Services.BuildServiceProvider().GetService <ResourceStorageContext>(); Assert.IsNotNull(storageContext); var store = new ResourceStore(storageContext, _logger); Assert.IsNotNull(store); string name = Guid.NewGuid().ToString("n"); var resource = CreateApiTestObject(name); 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 resources = await store.GetAllResourcesAsync(); int count = resources.ApiResources.Count(); stopwatch.Stop(); Console.WriteLine($"ResourceStore.GetAllResourcesAsync().ApiResources.Count: {count} : {stopwatch.ElapsedMilliseconds} ms"); Assert.IsNotNull(resources.ApiResources.FirstOrDefault(f => f.Name == name)); //Remove stopwatch.Reset(); stopwatch.Start(); await store.RemoveApiResourceAsync(resource.Name); 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($"ResourceStore.FindResourceByIdAsync({resource.Name})-api: {stopwatch.ElapsedMilliseconds} ms"); Assert.IsNull(findResource); }
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.FindIdentityResourcesByScopeNameAsync(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); }