Example #1
0
        public async Task DeleteIdentityResourceAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleAsync();

                //Assert new identity resource
                newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id));

                //Delete identity resource
                await identityResourceRepository.DeleteIdentityResourceAsync(newIdentityResource);

                //Get deleted identity resource
                var deletedIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleOrDefaultAsync();

                //Assert if it not exist
                deletedIdentityResource.Should().BeNull();
            }
        }
Example #2
0
        public async Task UpdateIdentityResourceAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleOrDefaultAsync();

                //Assert new identity resource
                newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(newIdentityResource).State = EntityState.Detached;

                //Generete new identity resource with added item id
                var updatedIdentityResource = IdentityResourceMock.GenerateRandomIdentityResource(newIdentityResource.Id);

                //Update identity resource
                await identityResourceRepository.UpdateIdentityResourceAsync(updatedIdentityResource);

                //Get updated identity resource
                var updatedIdentityResourceEntity = await context.IdentityResources.Where(x => x.Id == updatedIdentityResource.Id).SingleAsync();

                //Assert updated identity resource
                updatedIdentityResource.ShouldBeEquivalentTo(updatedIdentityResourceEntity);
            }
        }
Example #3
0
        public async Task GetIdentityResourcePropertyAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource without id
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id);

                //Assert new identity resource
                resource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id).Excluding(o => o.UserClaims));

                resource.UserClaims.ShouldBeEquivalentTo(identityResource.UserClaims,
                                                         option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id"))
                                                         .Excluding(x => x.SelectedMemberPath.EndsWith("IdentityResource")));

                //Generate random new identity resource property
                var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0);

                //Add new identity resource property
                await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty);

                //Get new identity resource property
                var resourceProperty = await identityResourceRepository.GetIdentityResourcePropertyAsync(identityResourceProperty.Id);

                resourceProperty.ShouldBeEquivalentTo(identityResourceProperty,
                                                      options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource));
            }
        }
Example #4
0
        public async Task AddIdentityResourcePropertyAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource without id
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id);

                //Assert new identity resource
                resource.Should().BeEquivalentTo(identityResource, options => options.Excluding(o => o.Id));

                //Generate random new identity resource property
                var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0);

                //Add new identity resource property
                await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty);

                //Get new identity resource property
                var resourceProperty = await context.IdentityResourceProperties.Where(x => x.Id == identityResourceProperty.Id)
                                       .SingleOrDefaultAsync();

                resourceProperty.Should().BeEquivalentTo(identityResourceProperty,
                                                         options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource));
            }
        }
Example #5
0
        public async Task GetIdentityResourcePropertyAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource without id
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id);

                //Assert new identity resource
                resource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id));

                //Generate random new identity resource property
                var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0);

                //Add new identity resource property
                await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty);

                //Get new identity resource property
                var resourceProperty = await identityResourceRepository.GetIdentityResourcePropertyAsync(identityResourceProperty.Id);

                resourceProperty.ShouldBeEquivalentTo(identityResourceProperty,
                                                      options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource));
            }
        }
Example #6
0
        public async Task GetScopesIdentityResourceAsync()
        {
            IClientRepository           clientRepository           = new ClientDapperRepository(_configuration);
            IIdentityResourceRepository identityResourceRepository = new IdentityResourceDapperRepository(_configuration);

            var identityResource = IdentityResourceMock.GenerateRandomIdentityResource();
            await identityResourceRepository.AddIdentityResourceAsync(identityResource);

            var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name);

            identityScopes[0].Should().Be(identityResource.Name);
        }
        public async Task GetScopesIdentityResourceAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var clientRepository           = GetClientRepository(context);
                var identityResourceRepository = GetIdentityResourceRepository(context);

                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name);

                identityScopes[0].Should().Be(identityResource.Name);
            }
        }
        public async Task GetScopesIdentityResourceAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository           clientRepository           = new ClientRepository(context);
                IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context);


                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name);

                identityScopes[0].Should().Be(identityResource.Name);
            }
        }
Example #9
0
        public void CanMapIdentityResourceToModel()
        {
            //Generate entity
            var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(1);

            //Try map to DTO
            var identityResourceDto = identityResource.ToModel();

            //Asert
            identityResourceDto.Should().NotBeNull();

            identityResource.Should().BeEquivalentTo(identityResourceDto, options =>
                                                     options.Excluding(o => o.UserClaims));

            //Assert collection
            identityResource.UserClaims.Select(x => x.Type).Should().BeEquivalentTo(identityResourceDto.UserClaims);
        }
Example #10
0
        public async Task GetIdentityResourceAsync()
        {
            using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context);

                //Generate random new identity resource
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var newIdentityResource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id);

                //Assert new identity resource
                newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id));
            }
        }
Example #11
0
        public async Task AddIdentityResourceAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleAsync();

                //Assert new identity resource
                newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id));
            }
        }
Example #12
0
        public async Task GetIdentityResourceAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var identityResourceRepository = GetIdentityResourceRepository(context);

                //Generate random new identity resource
                var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0);

                //Add new identity resource
                await identityResourceRepository.AddIdentityResourceAsync(identityResource);

                //Get new identity resource
                var newIdentityResource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id);

                //Assert new identity resource
                newIdentityResource.Should().BeEquivalentTo(identityResource, options => options.Excluding(o => o.Id).Excluding(o => o.UserClaims));

                newIdentityResource.UserClaims.Should().BeEquivalentTo(identityResource.UserClaims,
                                                                       option => option.Excluding(x => x.Path.EndsWith("Id"))
                                                                       .Excluding(x => x.Path.EndsWith("IdentityResource")));
            }
        }