public static ApiScope ToApiScope(this Entity.ApiScope apiScope) { if (apiScope == null) { return(null); } var cultureId = CultureInfo.CurrentCulture.Name; var resources = apiScope.Resources; return(new ApiScope { Description = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.Description && r.CultureId == cultureId)?.Value ?? apiScope.Description, DisplayName = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.DisplayName && r.CultureId == cultureId)?.Value ?? apiScope.DisplayName, Emphasize = apiScope.Emphasize, Name = apiScope.Id, Required = apiScope.Required, ShowInDiscoveryDocument = apiScope.ShowInDiscoveryDocument, UserClaims = apiScope.ApiScopeClaims .Select(c => c.Type).ToList(), Properties = apiScope.Properties .ToDictionary(p => p.Key, p => p.Value) }); }
public async Task DeleteAsync_should_remove_entity_id_from_parents() { using var store = new RavenDbTestDriverWrapper().GetDocumentStore(); var entity = new Entity.ApiApiScope { Id = Guid.NewGuid().ToString(), ApiId = "test", ApiScopeId = "test" }; var api = new Entity.ProtectResource { Id = "test", ApiScopes = new List <Entity.ApiApiScope> { new Entity.ApiApiScope { Id = $"{typeof(Entity.ApiApiScope).Name.ToLowerInvariant()}/{entity.Id}" } } }; var apiScope = new Entity.ApiScope { Id = "test", Apis = new List <Entity.ApiApiScope> { new Entity.ApiApiScope { Id = $"{typeof(Entity.ApiApiScope).Name.ToLowerInvariant()}/{entity.Id}" } } }; using var s1 = store.OpenAsyncSession(); await s1.StoreAsync(api, $"{nameof(Entity.ProtectResource).ToLowerInvariant()}/{api.Id}"); await s1.StoreAsync(apiScope, $"{nameof(Entity.ApiScope).ToLowerInvariant()}/{apiScope.Id}"); await s1.StoreAsync(entity, $"{typeof(Entity.ApiApiScope).Name.ToLowerInvariant()}/{entity.Id}"); await s1.SaveChangesAsync(); var loggerMock = new Mock <ILogger <AdminStore <Entity.ApiApiScope> > >(); using var session = store.OpenAsyncSession(); var sut = new ApiApiScopeStore(new ScopedAsynDocumentcSession(session), loggerMock.Object); await sut.DeleteAsync(entity.Id); using var s2 = store.OpenAsyncSession(); var apiUpdated = await s2.LoadAsync <Entity.ProtectResource>($"{nameof(Entity.ProtectResource).ToLowerInvariant()}/test"); Assert.DoesNotContain(apiUpdated.ApiScopes, i => i.Id == $"{typeof(Entity.ApiApiScope).Name.ToLowerInvariant()}/{entity.Id}"); var apiScopeUpdated = await s2.LoadAsync <Entity.ApiScope>($"{nameof(Entity.ApiScope).ToLowerInvariant()}/test"); Assert.DoesNotContain(apiScopeUpdated.Apis, i => i.Id == $"{typeof(Entity.ApiApiScope).Name.ToLowerInvariant()}/{entity.Id}"); }
protected override ICollection <Entity.ApiScopeClaim> GetCollection(Entity.ApiScope apiScope) { if (apiScope.ApiScopeClaims == null) { apiScope.ApiScopeClaims = new List <Entity.ApiScopeClaim>(); } return(apiScope.ApiScopeClaims); }
protected override ICollection<Entity.ApiScopeProperty> GetCollection(Entity.ApiScope apiScope) { if (apiScope.Properties == null) { apiScope.Properties = new List<Entity.ApiScopeProperty>(); } return apiScope.Properties; }
public async Task DeleteAsync_should_remove_entity_id_from_parent() { using var store = new RavenDbTestDriverWrapper().GetDocumentStore(); var entity = new TEntity { Id = Guid.NewGuid().ToString(), ApiScopeId = "test" }; var api = new Entity.ApiScope { Id = "test", }; var collection = GetCollection(api); collection.Add(new TEntity { Id = $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}" }); using var s1 = store.OpenAsyncSession(); await s1.StoreAsync(api, $"{nameof(Entity.ApiScope).ToLowerInvariant()}/{api.Id}"); await s1.StoreAsync(entity, $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}"); await s1.SaveChangesAsync(); var loggerMock = new Mock <ILogger <AdminStore <TEntity> > >(); using var session = store.OpenAsyncSession(); var sut = CreateSut(session, loggerMock.Object); await sut.DeleteAsync(entity.Id); using var s2 = store.OpenAsyncSession(); var updated = await s2.LoadAsync <Entity.ApiScope>($"{nameof(Entity.ApiScope).ToLowerInvariant()}/test"); var updatedCollection = GetCollection(updated); Assert.DoesNotContain(updatedCollection, i => i.Id == $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}"); }
protected abstract ICollection <TEntity> GetCollection(Entity.ApiScope apiScope);
protected override ICollection <Entity.ApiScopeLocalizedResource> GetCollection(Entity.ApiScope apiScope) { if (apiScope.Resources == null) { apiScope.Resources = new List <Entity.ApiScopeLocalizedResource>(); } return(apiScope.Resources); }