public void Properties_Map() { var model = new ApiResource() { Description = "description", DisplayName = "displayname", Name = "foo", Scopes = { "foo1", "foo2" }, Enabled = false }; var mappedEntity = model.ToEntity(); mappedEntity.Scopes.Count.Should().Be(2); var foo1 = mappedEntity.Scopes.FirstOrDefault(x => x.Scope == "foo1"); foo1.Should().NotBeNull(); var foo2 = mappedEntity.Scopes.FirstOrDefault(x => x.Scope == "foo2"); foo2.Should().NotBeNull(); var mappedModel = mappedEntity.ToModel(); mappedModel.Description.Should().Be("description"); mappedModel.DisplayName.Should().Be("displayname"); mappedModel.Enabled.Should().BeFalse(); mappedModel.Name.Should().Be("foo"); }
public void Can_Map() { var model = new ApiResource(); var mappedEntity = model.ToEntity(); var mappedModel = mappedEntity.ToModel(); Assert.NotNull(mappedModel); Assert.NotNull(mappedEntity); }
public void missing_values_should_use_defaults() { var entity = new Duende.IdentityServer.EntityFramework.Entities.ApiResource { Secrets = new System.Collections.Generic.List <Duende.IdentityServer.EntityFramework.Entities.ApiResourceSecret> { new Duende.IdentityServer.EntityFramework.Entities.ApiResourceSecret { } } }; var def = new ApiResource { ApiSecrets = { new Duende.IdentityServer.Models.Secret("foo") } }; var model = entity.ToModel(); model.ApiSecrets.First().Type.Should().Be(def.ApiSecrets.First().Type); }
private static void SeedApiClaims(IAdminStore <Entity.ApiClaim> apiClaimStore, ISModels.ApiResource resource) { foreach (var claim in resource.UserClaims) { try { apiClaimStore.CreateAsync(new Entity.ApiClaim { ApiId = resource.Name, Id = Guid.NewGuid().ToString(), Type = claim }).GetAwaiter().GetResult(); } catch (ArgumentException) { // silent } } }
private static void SeedApiSecrets(IAdminStore <Entity.ApiSecret> apiSecretStore, ISModels.ApiResource resource) { foreach (var secret in resource.ApiSecrets) { try { apiSecretStore.CreateAsync(new Entity.ApiSecret { ApiId = resource.Name, Expiration = secret.Expiration, Description = secret.Description, Id = Guid.NewGuid().ToString(), Type = secret.Type, Value = secret.Value }).GetAwaiter().GetResult(); } catch (ArgumentException) { // silent } } }
private static void SeedApiApiScopes(IAdminStore <Entity.ApiApiScope> apiApiScopeStore, ISModels.ApiResource resource) { foreach (var apiScope in resource.Scopes) { try { apiApiScopeStore.CreateAsync(new Entity.ApiApiScope { ApiId = resource.Name, ApiScopeId = apiScope, Id = Guid.NewGuid().ToString() }).GetAwaiter().GetResult(); } catch (ArgumentException) { // silent } } }
private static void SeedApiProperties(IAdminStore <Entity.ApiProperty> apiPropertyStore, ISModels.ApiResource resource) { foreach (var property in resource.Properties) { try { apiPropertyStore.CreateAsync(new Entity.ApiProperty { ApiId = resource.Name, Id = Guid.NewGuid().ToString(), Key = property.Key, Value = property.Value }).GetAwaiter().GetResult(); } catch (ArgumentException) { // silent } } }