public void Map_Use_Defaults_Missing_ThrowsException() { // Arrange var entity = new Entities.ApiResource { // Name = Guid.NewGuid().ToString(), DisplayName = Guid.NewGuid().ToString(), Secrets = new System.Collections.Generic.List <Entities.ApiSecret> { new Entities.ApiSecret { } } }; var def = new Models.ApiResource { ApiSecrets = { new Models.Secret("foo") } }; // Act & Assert Assert.ThrowsException <ArgumentNullException>(() => ApiResourceMappers.ToModel(entity)); }
public void Map_Use_Defaults() { // Arrange var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ApiResourceMapperProfile>(); }); var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration)); var entity = new Entities.ApiResource { Secrets = new System.Collections.Generic.List <Entities.ApiSecret> { new Entities.ApiSecret { } } }; var def = new Models.ApiResource { ApiSecrets = { new Models.Secret("foo") } }; // Act var mappedModel = mapper.Map <Models.ApiResource>(entity); // Assert Assert.Equal(def.ApiSecrets.First().Type, mappedModel.ApiSecrets.First().Type); }
public void Map_Use_Defaults() { // Arrange var entity = new Entities.ApiResource { Name = Guid.NewGuid().ToString(), DisplayName = Guid.NewGuid().ToString(), Secrets = new System.Collections.Generic.List <Entities.ApiSecret> { new Entities.ApiSecret { } } }; var def = new Models.ApiResource { ApiSecrets = { new Models.Secret("foo") } }; // Act var mappedModel = ApiResourceMappers.ToModel(entity); // Assert Assert.AreEqual(def.ApiSecrets.First().Type, mappedModel.ApiSecrets.First().Type); }
public void Properties_Map() { ApiResource model = new ApiResource { Description = "description", DisplayName = "displayname", Name = "foo", Scopes = { "foo1", "foo2" }, Enabled = false }; Entities.ApiResource mappedEntity = model.ToEntity(); mappedEntity.Scopes.Count.Should().Be(2); string foo1 = mappedEntity.Scopes.FirstOrDefault(x => x == "foo1"); foo1.Should().NotBeNull(); string foo2 = mappedEntity.Scopes.FirstOrDefault(x => x == "foo2"); foo2.Should().NotBeNull(); ApiResource 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() { ApiResource model = new ApiResource(); Entities.ApiResource mappedEntity = model.ToEntity(); ApiResource mappedModel = mappedEntity.ToModel(); Assert.NotNull(mappedModel); Assert.NotNull(mappedEntity); }
public void missing_values_should_use_defaults() { Entities.ApiResource entity = new Entities.ApiResource { Secrets = new List <Secret> { new Secret() } }; ApiResource def = new ApiResource { ApiSecrets = { new Models.Secret("foo") } }; ApiResource model = entity.ToModel(); model.ApiSecrets.First().Type.Should().Be(def.ApiSecrets.First().Type); }
public void ToModel_MapsAllowedIdentityTokenSigningAlgorithms() { var apiResource = new Entities.ApiResource() { AllowedAccessTokenSigningAlgorithms = "HS256,ES256" }; var entity = apiResource.ToModel(); Assert.NotNull(apiResource.AllowedAccessTokenSigningAlgorithms); Assert.NotEmpty(entity.AllowedAccessTokenSigningAlgorithms); var algorithms = entity.AllowedAccessTokenSigningAlgorithms.ToList(); var algorithmOne = algorithms[0]; var algorithmTwo = algorithms[1]; Assert.Equal("HS256", algorithmOne); Assert.Equal("ES256", algorithmTwo); }
/// <summary> /// Maps an entity to a model. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public static IdentityServer4.Models.ApiResource ToModel(this Entities.ApiResource entity) { return(Mapper.Map <IdentityServer4.Models.ApiResource>(entity)); }
public static Models.ApiResource ToModel(this Entities.ApiResource resource) { return(resource == null ? null : Mapper.Map <Models.ApiResource>(resource)); }
public static Models.ApiResource ToModel(this Entities.ApiResource entity) { return(entity == null ? null : Mapper.Map <Models.ApiResource>(entity)); }
public static ApiResource ToModel(this Entities.ApiResource entity) { if (entity is null) { return(default);
public void RemoveApiResource(Entities.ApiResource dbReource) { _apiResources.Remove(dbReource.Id); }
public void AddApiResource(Entities.ApiResource entity) { _apiResources.Add(entity); }
/// <summary> /// 转换成model /// </summary> /// <param name="entity"></param> /// <returns></returns> public static EditResourcesViewModel ToModel(this Entities.ApiResource entity) { return(Mapper.Map <EditResourcesViewModel>(entity)); }