コード例 #1
0
        public async Task DeleteApiScopeAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var apiResourceRepository = GetApiResourceRepository(context);

                //Generate random new api resource
                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);

                //Add new api resource
                await apiResourceRepository.AddApiResourceAsync(apiResource);

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

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

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

                //Assert new api resource
                newApiScopes.ShouldBeEquivalentTo(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();
            }
        }
コード例 #2
0
        public async Task GetApiScopeAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var apiResourceRepository = GetApiResourceRepository(context);

                //Generate random new api resource
                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);

                //Add new api resource
                await apiResourceRepository.AddApiResourceAsync(apiResource);

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

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

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

                //Assert new api resource
                newApiScopes.ShouldBeEquivalentTo(apiScope, options => options.Excluding(o => o.Id));
            }
        }
コード例 #3
0
        public async Task GetApiScopeAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiResourceRepository(context);

                //Generate random new api resource
                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);

                //Add new api resource
                await apiResourceRepository.AddApiResourceAsync(apiResource);

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

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

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

                //Assert new api resource
                newApiScopes.ShouldBeEquivalentTo(apiScope, options => options.Excluding(o => o.Id)
                                                  .Excluding(o => o.UserClaims)
                                                  .Excluding(o => o.ApiResource.Secrets)
                                                  .Excluding(o => o.ApiResource.UserClaims)
                                                  .Excluding(o => o.ApiResource.Scopes));

                newApiScopes.UserClaims.ShouldBeEquivalentTo(apiScope.UserClaims,
                                                             option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id"))
                                                             .Excluding(x => x.SelectedMemberPath.EndsWith("ApiScope")));
            }
        }
コード例 #4
0
        public async Task AddApiScopeAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiResourceRepository(context);

                //Generate random new api resource
                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);

                //Add new api resource
                await apiResourceRepository.AddApiResourceAsync(apiResource);

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

                //Add new api scope
                await apiResourceRepository.AddApiScopeAsync(apiResource.Id, 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));
            }
        }
コード例 #5
0
        public async Task DeleteApiScopeAsync()
        {
            IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration);

            //Generate random new api resource
            var apiResource = ApiResourceMock.GenerateRandomApiResource();

            //Add new api resource
            var apiResourceId = await apiResourceRepository.AddApiResourceAsync(apiResource);

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

            //Add new api resource
            var apiScopeId = await apiResourceRepository.AddApiScopeAsync(apiResourceId, apiScope);

            //Get new api resource
            var newApiScopes = await apiResourceRepository.GetApiScopeAsync(apiResourceId, apiScopeId);

            //Assert new api resource
            newApiScopes.ShouldBeEquivalentTo(apiScope, options => options.Excluding(o => o.Id)
                                              .Excluding(o => o.ApiResource)
                                              .Excluding(o => o.Id).Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "UserClaims\\[.+\\].Id")));

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

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

            //Assert if it exist
            deletedApiScopes.Should().BeNull();
        }
コード例 #6
0
        public async Task UpdateApiScopeAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var apiResourceRepository = GetApiResourceRepository(context);

                //Generate random new api resource
                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);

                //Add new api resource
                await apiResourceRepository.AddApiResourceAsync(apiResource);

                //Get new api resource
                var newApiResource = await context.ApiResources.Where(x => x.Id == apiResource.Id).SingleOrDefaultAsync();

                //Assert new api resource
                newApiResource.ShouldBeEquivalentTo(apiResource, options => options.Excluding(o => o.Id));

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

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

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

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

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

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

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

                //Assert updated api scope
                updatedApiScope.ShouldBeEquivalentTo(updatedApiScopeEntity);
            }
        }
コード例 #7
0
        public async Task GetScopesApiResourceAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository      clientRepository      = new ClientRepository(context);
                IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context);

                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);
                await apiResourceRepository.AddApiResourceAsync(apiResource);

                var resource = await context.ApiResources.Where(x => x.Name == apiResource.Name).SingleOrDefaultAsync();

                var apiScope = ApiResourceMock.GenerateRandomApiScope(0);
                await apiResourceRepository.AddApiScopeAsync(resource.Id, apiScope);

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

                apiScopes[0].Should().Be(apiScope.Name);
            }
        }
コード例 #8
0
        public async Task GetScopesApiResourceAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var clientRepository      = GetClientRepository(context);
                var apiResourceRepository = GetApiResourceRepository(context);

                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);
                await apiResourceRepository.AddApiResourceAsync(apiResource);

                var resource = await context.ApiResources.Where(x => x.Name == apiResource.Name).SingleOrDefaultAsync();

                var apiScope = ApiResourceMock.GenerateRandomApiScope(0);
                await apiResourceRepository.AddApiScopeAsync(resource.Id, apiScope);

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

                apiScopes[0].Should().Be(apiScope.Name);
            }
        }
コード例 #9
0
        public async Task UpdateApiScopeAsync()
        {
            IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration);

            //Generate random new api resource
            var apiResource = ApiResourceMock.GenerateRandomApiResource();

            //Add new api resource
            var apiResourceId = await apiResourceRepository.AddApiResourceAsync(apiResource);

            //Get new api resource
            var newApiResource = await apiResourceRepository.GetApiResourceAsync(apiResourceId);

            //Assert new api resource
            newApiResource.ShouldBeEquivalentTo(apiResource, options => options.Excluding(o => o.Id).Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "UserClaims\\[.+\\].Id")));

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

            //Add new api scope
            var apiScopeId = await apiResourceRepository.AddApiScopeAsync(apiResourceId, apiScope);

            //Generete new api scope with added item id
            var updatedApiScope = ApiResourceMock.GenerateRandomApiScope(apiScopeId);

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

            //Get updated api scope
            var updatedApiScopeEntity = await apiResourceRepository.GetApiScopeAsync(apiResourceId, updatedApiScope.Id);

            //Assert updated api scope
            updatedApiScope.ShouldBeEquivalentTo(updatedApiScopeEntity, options => options.Excluding(o => o.ApiResource)
                                                 .Excluding(o => o.Id)
                                                 .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "UserClaims\\[.+\\].Id")));
        }