public void CanMapIdentityResource()
        {
            var mapper       = new MapperConfiguration(cfg => cfg.AddProfile <ResourceProfile>()).CreateMapper();
            var model        = new Models.IdentityResource();
            var mappedEntity = mapper.Map <Entities.IdentityResource>(model);
            var mappedModel  = mapper.Map <Models.IdentityResource>(mappedEntity);

            Assert.NotNull(mappedEntity);
            Assert.NotNull(mappedModel);
        }
        public void Map()
        {
            var model  = new Models.IdentityResource();
            var entity = IdentityResourceMappers.ToEntity(model);

            model = IdentityResourceMappers.ToModel(entity);

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNotNull(model);
        }
        public async Task GetAllResources_WhenAllResourcesRequested_ExpectAllResourcesIncludingHidden()
        {
            // Arrange
            var visibleIdentityResource = UniqueIdentityResource;
            var visibleApiResource      = UniqueApiResource;
            var hiddenIdentityResource  =
                new Models.IdentityResource {
                Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false
            };
            var hiddenApiResource = new Models.ApiResource
            {
                Name   = Guid.NewGuid().ToString(),
                Scopes = new List <Models.Scope>
                {
                    new Models.Scope {
                        Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false
                    }
                }
            };



            await _operationalTestContext.AddApiResourceAsync(visibleApiResource);

            await _operationalTestContext.AddIdentityResourceAsync(visibleIdentityResource);

            await _operationalTestContext.AddApiResourceAsync(hiddenApiResource);

            await _operationalTestContext.AddIdentityResourceAsync(hiddenIdentityResource);


            var resources = await _resourceStore.GetAllResourcesAsync();

            // Assert
            Assert.IsNotNull(resources);
            Assert.IsTrue(resources.IdentityResources.Any());
            Assert.IsTrue(resources.ApiResources.Any());

            var anyDoNotShowIdentityResources = (from identityResource in resources.IdentityResources
                                                 where !identityResource.ShowInDiscoveryDocument
                                                 select identityResource).Any();
            var anyDoNotShowApiResources = (from apiResource in resources.ApiResources
                                            from scope in apiResource.Scopes
                                            where !scope.ShowInDiscoveryDocument
                                            select apiResource).Any();

            Assert.IsTrue(anyDoNotShowIdentityResources);
            Assert.IsTrue(anyDoNotShowApiResources);
        }
Esempio n. 4
0
 public static IdentityResource ToEntity(this Models.IdentityResource model)
 {
     return(model == null ? null : new IdentityResource
     {
         Description = model.Description,
         DisplayName = model.DisplayName,
         Emphasize = model.Emphasize,
         Enabled = model.Enabled,
         Name = model.Name,
         Properties = model.Properties,
         Required = model.Required,
         ShowInDiscoveryDocument = model.ShowInDiscoveryDocument,
         UserClaims = model.UserClaims?.ToList()
     });
 }
        public void Map()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <IdentityResourceMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));
            var model  = new Models.IdentityResource();

            // Act
            var entity = mapper.Map <Entities.IdentityResource>(model);

            model = mapper.Map <Models.IdentityResource>(entity);

            // Assert
            Assert.NotNull(entity);
            Assert.NotNull(model);
            mapperConfiguration.AssertConfigurationIsValid();
        }
Esempio n. 6
0
        public async Task GetAllResources_WhenAllResourcesRequested_ExpectAllResourcesIncludingHidden()
        {
            // Arrange
            var visibleIdentityResource = CreateIdentityTestResource();
            var visibleApiResource      = CreateApiTestResource();
            var hiddenIdentityResource  = new Models.IdentityResource {
                Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false
            };
            var hiddenApiResource = new Models.ApiResource
            {
                Name   = Guid.NewGuid().ToString(),
                Scopes = new List <Models.Scope> {
                    new Models.Scope {
                        Name = Guid.NewGuid().ToString(), ShowInDiscoveryDocument = false
                    }
                }
            };

            var mapper = _hostContainer.Container.Resolve <IMapper>();

            var identityResourceRepository = _hostContainer.Container.Resolve <IRepository <Entities.IdentityResource> >();
            await identityResourceRepository.AddAsync(mapper.Map <Entities.IdentityResource>(visibleIdentityResource)).ConfigureAwait(false);

            await identityResourceRepository.AddAsync(mapper.Map <Entities.IdentityResource>(hiddenIdentityResource)).ConfigureAwait(false);

            var apiResourceRepository = _hostContainer.Container.Resolve <IRepository <Entities.ApiResource> >();
            await apiResourceRepository.AddAsync(mapper.Map <Entities.ApiResource>(visibleApiResource)).ConfigureAwait(false);

            await apiResourceRepository.AddAsync(mapper.Map <Entities.ApiResource>(hiddenApiResource)).ConfigureAwait(false);

            // Act
            var resourceStore = _hostContainer.Container.Resolve <IResourceStore>();
            var resources     = await resourceStore.GetAllResourcesAsync().ConfigureAwait(false);

            // Assert
            Assert.NotNull(resources);
            Assert.NotEmpty(resources.IdentityResources);
            Assert.NotEmpty(resources.ApiResources);
            Assert.Contains(resources.IdentityResources, x => !x.ShowInDiscoveryDocument);
            Assert.Contains(resources.ApiResources, x => !x.Scopes.Any(y => y.ShowInDiscoveryDocument));
        }
Esempio n. 7
0
 /// <summary>
 /// Maps a model to an entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns></returns>
 public static IdentityResource ToEntity(this Models.IdentityResource model)
 {
     return(model == null ? null : Mapper.Map <IdentityResource>(model));
 }
Esempio n. 8
0
 public static Documents.IdentityResource ToDocument(this Models.IdentityResource resource)
 {
     return(resource == null ? null : Mapper.Map <Documents.IdentityResource>(resource));
 }
 public static IdentityResource ToEntity(this Models.IdentityResource resource)
 {
     return(resource == null ? null : Mapper.Map <IdentityResource>(resource));
 }