public async Task FindIdentityResourcesByScopeNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateIdentityTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.IdentityResources.Add(resource.ToEntity()); context.SaveChanges(); } IList <IdentityResource> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(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 FindIdentityResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned(DbContextOptions <ConfigurationDbContext> options) { var resource = CreateIdentityTestResource(); using (var context = new ConfigurationDbContext(options, StoreOptions)) { context.IdentityResources.Add(resource.ToEntity()); context.IdentityResources.Add(CreateIdentityTestResource().ToEntity()); context.SaveChanges(); } IList <IdentityResource> resources; using (var context = new ConfigurationDbContext(options, StoreOptions)) { var store = new ResourceStore(context, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name })).ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
public async Task FindIdentityResourcesByScopeNameAsync_should_find_identity_by_name() { using var store = new RavenDbTestDriverWrapper().GetDocumentStore(); using var s1 = store.OpenAsyncSession(); await s1.StoreAsync(new Entity.IdentityResource { Id = "test", Resources = new List <Entity.IdentityLocalizedResource> { new Entity.IdentityLocalizedResource { Id = $"{nameof(Entity.IdentityLocalizedResource).ToLowerInvariant()}/test" } } }, $"{nameof(Entity.IdentityResource).ToLowerInvariant()}/test"); await s1.StoreAsync(new Entity.IdentityLocalizedResource { Id = "test", IdentityId = "test", ResourceKind = Entity.EntityResourceKind.DisplayName, Value = "test" }, $"{nameof(Entity.IdentityLocalizedResource).ToLowerInvariant()}/test"); await s1.SaveChangesAsync(); var sut = new ResourceStore(new ScopedAsynDocumentcSession(store.OpenAsyncSession())); var result = await sut.FindIdentityResourcesByScopeNameAsync(new[] { "test" }); Assert.NotEmpty(result); }
public async Task FindIdentityResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned() { using var ravenStore = GetDocumentStore(); await new IdentityResourceIndex().ExecuteAsync(ravenStore); var resource = CreateIdentityTestResource(); using (var session = ravenStore.OpenSession()) { session.Store(resource.ToEntity()); session.Store(CreateIdentityTestResource().ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IList <IdentityResource> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name })).ToList(); } Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
public async Task FindIdentityResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned() { var storeHolder = GetConfigurationDocumentStoreHolder(); var resource = CreateIdentityTestResource(); using (var session = storeHolder.OpenAsyncSession()) { await session.StoreAsync(resource.ToEntity()); await session.StoreAsync(CreateIdentityTestResource().ToEntity()); await session.SaveChangesAsync(); } WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore()); var store = new ResourceStore(storeHolder, FakeLogger <ResourceStore> .Create()); var resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name })).ToList(); Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
public async Task FindIdentityResourcesByScopeNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned() { using var ravenStore = GetDocumentStore(); await new IdentityResourceIndex().ExecuteAsync(ravenStore); var resource = CreateIdentityTestResource(); using (var session = ravenStore.OpenSession()) { session.Store(resource.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IList <IdentityResource> resources; using (var session = ravenStore.OpenAsyncSession()) { var store = new ResourceStore(session, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name, "non-existent" })).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 FindIdentityResourcesByScopeNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned() { var storeHolder = GetConfigurationDocumentStoreHolder(); var resource = CreateIdentityTestResource(); using (var session = storeHolder.OpenAsyncSession()) { await session.StoreAsync(resource.ToEntity()); await session.SaveChangesAsync(); } WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore()); var store = new ResourceStore(storeHolder, FakeLogger <ResourceStore> .Create()); var resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name, "non-existent" })).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 FindIdentityResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned() { var resource = CreateIdentityTestResource(); var entity = resource.ToEntity(); var repo = g.configurationDb.GetRepository <Storage.Entities.IdentityResource>(); repo.Insert(entity); repo.SaveMany(entity, "UserClaims"); repo.SaveMany(entity, "Properties"); IList <IdentityResource> resources; var store = new ResourceStore(g.configurationDb, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name })).ToList(); Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
public async Task Should_Retrieve_Only_Requested_Identity_Resources(TestDatabase testDb) { var testIdentityResource1 = CreateTestIdentityResource(Guid.NewGuid().ToString()); var testIdentityResource2 = CreateTestIdentityResource(Guid.NewGuid().ToString()); using (var session = testDb.OpenSession()) { await session.SaveAsync(testIdentityResource1.ToEntity()); await session.SaveAsync(testIdentityResource2.ToEntity()); await session.FlushAsync(); } var loggerMock = new Mock <ILogger <ResourceStore> >(); IEnumerable <IdentityResource> resources; using (var session = testDb.OpenStatelessSession()) { var store = new ResourceStore(session, loggerMock.Object); resources = (await store.FindIdentityResourcesByScopeNameAsync(new[] { testIdentityResource1.Name })) .ToList(); } resources.Should().NotBeEmpty(); resources.Count().Should().Be(1); await CleanupTestDataAsync(testDb); }
public async Task Should_Retrieve_Identity_Resource_And_Its_Claims_By_Scope(TestDatabase testDb) { const string testIdentityResourceName = "idres1"; var testIdentityResource = CreateTestIdentityResource(testIdentityResourceName); using (var session = testDb.OpenSession()) { await session.SaveAsync(testIdentityResource.ToEntity()); await session.FlushAsync(); } var loggerMock = new Mock <ILogger <ResourceStore> >(); IEnumerable <IdentityResource> resources; using (var session = testDb.OpenStatelessSession()) { var store = new ResourceStore(session, loggerMock.Object); resources = (await store.FindIdentityResourcesByScopeNameAsync(new[] { testIdentityResourceName })).ToList(); } resources.Should().NotBeEmpty(); resources.Count().Should().Be(1); resources.First().Name.Should().Be(testIdentityResourceName); resources.First().UserClaims.Count.Should().Be(2); await CleanupTestDataAsync(testDb); }
public async Task Can_call_ResourceStore_FindIdentityResourcesByScopeNameAsync() => await ExecuteWithStrategyInTransactionAsync( async context => { await SaveIdentityResources(context); }, async context => { var store = new ResourceStore(context, new FakeLogger <ResourceStore>()); Assert.Equal( 2, (await store.FindIdentityResourcesByScopeNameAsync(new[] { "IdentityResource2", "IdentityResource1" })).Count()); } );
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); }
public async Task FindIdentityResourcesByScopeNameAsync_WhenResourcesExist_ExpectOnlyRequestedReturned() { var resource = CreateIdentityTestResource(); await _context.IdentityResources.AddAsync(resource.ToEntity()); await _context.IdentityResources.AddAsync(CreateIdentityTestResource().ToEntity()); IList <IdentityResource> resources; var store = new ResourceStore(_context, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(new List <string> { resource.Name })).ToList(); Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.NotNull(resources.Single(x => x.Name == resource.Name)); }
public async Task FindIdentityResourcesByScopeNameAsync_WhenResourceExists_ExpectResourceAndCollectionsReturned() { var resource = CreateIdentityTestResource(); await _context.IdentityResources.AddAsync(resource.ToEntity()); IList <IdentityResource> resources; var store = new ResourceStore(_context, FakeLogger <ResourceStore> .Create()); resources = (await store.FindIdentityResourcesByScopeNameAsync(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); }