public async Task DeleteApiScopeAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiScopeRepository(context);

                //Generate random new api scope
                var apiScope = ApiScopeMock.GenerateRandomApiScope(0);

                //Add new api resource
                await apiResourceRepository.AddApiScopeAsync(apiScope);

                //Get new api resource
                var newApiScopes = await context.ApiScopes.Where(x => x.Id == apiScope.Id).SingleOrDefaultAsync();

                //Assert new api resource
                newApiScopes.Should().BeEquivalentTo(apiScope, options => options.Excluding(o => o.Id));

                //Try delete it
                await apiResourceRepository.DeleteApiScopeAsync(newApiScopes);

                //Get new api scope
                var deletedApiScopes = await context.ApiScopes.Where(x => x.Id == newApiScopes.Id).SingleOrDefaultAsync();

                //Assert if it exist
                deletedApiScopes.Should().BeNull();
            }
        }
        public async Task UpdateApiScopeAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiScopeRepository(context);

                //Generate random new api scope
                var apiScope = ApiScopeMock.GenerateRandomApiScope(0);

                //Add new api scope
                await apiResourceRepository.AddApiScopeAsync(apiScope);

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

                //Generete new api scope with added item id
                var updatedApiScope = ApiScopeMock.GenerateRandomApiScope(apiScope.Id);

                //Update api scope
                await apiResourceRepository.UpdateApiScopeAsync(updatedApiScope);

                //Get updated api scope
                var updatedApiScopeEntity = await context.ApiScopes.Where(x => x.Id == updatedApiScope.Id).SingleAsync();

                //Assert updated api scope
                updatedApiScope.Should().BeEquivalentTo(updatedApiScopeEntity);
            }
        }
        public async Task GetScopesApiResourceAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var clientRepository   = GetClientRepository(context);
                var apiScopeRepository = GetApiScopeRepository(context);

                var apiScope = ApiScopeMock.GenerateRandomApiScope(0);
                await apiScopeRepository.AddApiScopeAsync(apiScope);

                var apiScopes = await clientRepository.GetScopesAsync(apiScope.Name);

                apiScopes[0].Should().Be(apiScope.Name);
            }
        }
        public async Task AddApiScopeAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiScopeRepository(context);

                //Generate random new api scope
                var apiScope = ApiScopeMock.GenerateRandomApiScope(0);

                //Add new api scope
                await apiResourceRepository.AddApiScopeAsync(apiScope);

                //Get new api scope
                var newApiScopes = await context.ApiScopes.Where(x => x.Id == apiScope.Id).SingleAsync();

                //Assert new api scope
                newApiScopes.ShouldBeEquivalentTo(apiScope, options => options.Excluding(o => o.Id));
            }
        }
        public void CanMapApiScopeToModel()
        {
            //Generate DTO
            var apiScopeDto = ApiScopeMock.GenerateRandomApiScope(1);

            //Try map to entity
            var apiScope = apiScopeDto.ToModel();

            apiScope.Should().NotBeNull();

            apiScope.ShouldBeEquivalentTo(apiScopeDto, options =>
                                          options.Excluding(o => o.UserClaims)
                                          .Excluding(o => o.ApiScopeProperties)
                                          .Excluding(o => o.UserClaimsItems));

            //Assert collection
            apiScopeDto.UserClaims.Select(x => x.Type).ShouldBeEquivalentTo(apiScope.UserClaims);
            apiScope.Id.Should().Be(apiScopeDto.Id);
        }
        public async Task GetApiScopeAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiScopeRepository(context);

                //Generate random new api scope
                var apiScope = ApiScopeMock.GenerateRandomApiScope(0);

                //Add new api scope
                await apiResourceRepository.AddApiScopeAsync(apiScope);

                //Get new api scope
                var newApiScopes = await apiResourceRepository.GetApiScopeAsync(apiScope.Id);

                //Assert new api resource
                newApiScopes.Should().BeEquivalentTo(apiScope, options => options.Excluding(o => o.Id)
                                                     .Excluding(o => o.UserClaims));

                newApiScopes.UserClaims.Should().BeEquivalentTo(apiScope.UserClaims,
                                                                option => option.Excluding(x => x.Path.EndsWith("Id"))
                                                                .Excluding(x => x.Path.EndsWith("Scope")));
            }
        }