public async Task AddApiScopeAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(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)); } }
public async Task DeleteApiResourceAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(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).SingleAsync(); //Assert new api resource newApiResource.ShouldBeEquivalentTo(apiResource, options => options.Excluding(o => o.Id)); //Delete api resource await apiResourceRepository.DeleteApiResourceAsync(newApiResource); //Get deleted api resource var deletedApiResource = await context.ApiResources.Where(x => x.Id == apiResource.Id).SingleOrDefaultAsync(); //Assert if it not exist deletedApiResource.Should().BeNull(); } }
public async Task GetApiSecretAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context); //Generate random new api resource var apiResource = ApiResourceMock.GenerateRandomApiResource(0); //Add new api resource await apiResourceRepository.AddApiResourceAsync(apiResource); //Generate random new api secret var apiSecret = ApiResourceMock.GenerateRandomApiSecret(0); //Add new api secret await apiResourceRepository.AddApiSecretAsync(apiResource.Id, apiSecret); //Get new api secret var newApiSecret = await apiResourceRepository.GetApiSecretAsync(apiSecret.Id); //Assert new api secret newApiSecret.ShouldBeEquivalentTo(apiSecret, options => options.Excluding(o => o.Id)); } }
public async Task GetApiResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context); IClientRepository clientRepository = new ClientRepository(context); var localizerApiResourceMock = new Mock <IApiResourceServiceResources>(); var localizerApiResource = localizerApiResourceMock.Object; var localizerClientResourceMock = new Mock <IClientServiceResources>(); var localizerClientResource = localizerClientResourceMock.Object; IClientService clientService = new ClientService(clientRepository, localizerClientResource); IApiResourceService apiResourceService = new ApiResourceService(apiResourceRepository, localizerApiResource, clientService); //Generate random new api resource var apiResourceDto = ApiResourceDtoMock.GenerateRandomApiResource(0); await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var apiResource = await context.ApiResources.Where(x => x.Name == apiResourceDto.Name).SingleOrDefaultAsync(); var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id); //Assert new api resource apiResourceDto.ShouldBeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id)); } }
public ApiResourceUoW(ISessionManager sessionManager, ApiResourceRepository apiResourceRepository, ClaimTypeRepository claimTypeRepository, ScopeRepository scopeRepository) : base(sessionManager) { m_apiResourceRepository = apiResourceRepository; m_claimTypeRepository = claimTypeRepository; m_scopeRepository = scopeRepository; }
public async Task UpdateApiResourceAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(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; //Generete new api resource with added item id var updatedApiResource = ApiResourceMock.GenerateRandomApiResource(newApiResource.Id); //Update api resource await apiResourceRepository.UpdateApiResourceAsync(updatedApiResource); //Get updated api resource var updatedApiResourceEntity = await context.ApiResources.Where(x => x.Id == updatedApiResource.Id).SingleAsync(); //Assert updated api resource updatedApiResource.ShouldBeEquivalentTo(updatedApiResourceEntity); } }
public async Task DeleteApiSecretAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context); IClientRepository clientRepository = new ClientRepository(context); var localizerApiResourceMock = new Mock <IApiResourceServiceResources>(); var localizerApiResource = localizerApiResourceMock.Object; var localizerClientResourceMock = new Mock <IClientServiceResources>(); var localizerClientResource = localizerClientResourceMock.Object; IClientService clientService = new ClientService(clientRepository, localizerClientResource); IApiResourceService apiResourceService = new ApiResourceService(apiResourceRepository, localizerApiResource, clientService); //Generate random new api resource var apiResourceDto = ApiResourceDtoMock.GenerateRandomApiResource(0); await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var apiResource = await context.ApiResources.Where(x => x.Name == apiResourceDto.Name).SingleOrDefaultAsync(); var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id); //Assert new api resource apiResourceDto.ShouldBeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id)); //Generate random new api secret var apiSecretsDtoMock = ApiResourceDtoMock.GenerateRandomApiSecret(0, newApiResourceDto.Id); //Add new api secret await apiResourceService.AddApiSecretAsync(apiSecretsDtoMock); //Get inserted api secret var apiSecret = await context.ApiSecrets.Where(x => x.Value == apiSecretsDtoMock.Value && x.ApiResource.Id == newApiResourceDto.Id) .SingleOrDefaultAsync(); //Map entity to model var apiSecretsDto = apiSecret.ToModel(); //Get new api secret var newApiSecret = await apiResourceService.GetApiSecretAsync(apiSecretsDto.ApiSecretId); //Assert newApiSecret.ShouldBeEquivalentTo(apiSecretsDto, o => o.Excluding(x => x.ApiResourceName)); //Delete it await apiResourceService.DeleteApiSecretAsync(newApiSecret); var deletedApiSecret = await context.ApiSecrets.Where(x => x.Value == apiSecretsDtoMock.Value && x.ApiResource.Id == newApiResourceDto.Id) .SingleOrDefaultAsync(); //Assert after deleting deletedApiSecret.Should().BeNull(); } }
public ClientUoW(ISessionManager sessionManager, ClientRepository clientRepository, GrantTypeRepository grantTypeRepository, IdentityResourceRepository identityResourceRepository, ApiResourceRepository apiResourceRepository, ScopeRepository scopeRepository) : base(sessionManager) { m_clientRepository = clientRepository; m_grantTypeRepository = grantTypeRepository; m_identityResourceRepository = identityResourceRepository; m_apiResourceRepository = apiResourceRepository; m_scopeRepository = scopeRepository; }
public virtual async Task <Resources> GetAllResourcesAsync() { var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails : true); var apiResources = await ApiResourceRepository.GetListAsync(includeDetails : true); return(new Resources( ObjectMapper.Map <List <IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources), ObjectMapper.Map <List <ApiResources.ApiResource>, ApiResource[]>(apiResources) )); }
/// <summary> /// Gets API resources by API resource name. /// </summary> public virtual async Task <IEnumerable <IdentityServer4.Models.ApiResource> > FindApiResourcesByNameAsync(IEnumerable <string> apiResourceNames) { return(await GetCacheItemsAsync( ApiResourceCache, apiResourceNames, async keys => await ApiResourceRepository.FindByNameAsync(keys, includeDetails: true), (models, cacheKeyPrefix) => new List <IEnumerable <KeyValuePair <string, IdentityServer4.Models.ApiResource> > > { models.Select(x => new KeyValuePair <string, IdentityServer4.Models.ApiResource>(AddCachePrefix(x.Name, cacheKeyPrefix), x)) }, ApiResourceNameCacheKeyPrefix)); }
/// <summary> /// Gets API resources by scope name. /// </summary> public virtual async Task <IEnumerable <IdentityServer4.Models.ApiResource> > FindApiResourcesByScopeNameAsync(IEnumerable <string> scopeNames) { return(await GetCacheItemsAsync <ApiResource, IdentityServer4.Models.ApiResource>( ApiResourceCache, scopeNames, async keys => await ApiResourceRepository.GetListByScopesAsync(keys, includeDetails: true), (models, cacheKeyPrefix) => { return models .Select(model => model.Scopes.Select(scope => new KeyValuePair <string, IdentityServer4.Models.ApiResource>(AddCachePrefix(scope, cacheKeyPrefix), model)).ToList()) .Where(scopes => scopes.Any()).Cast <IEnumerable <KeyValuePair <string, IdentityServer4.Models.ApiResource> > >().ToList(); }, ApiResourceScopeNameCacheKeyPrefix)); }
public async Task GetApiScopeAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context); IClientRepository clientRepository = new ClientRepository(context); var localizerApiResourceMock = new Mock <IApiResourceServiceResources>(); var localizerApiResource = localizerApiResourceMock.Object; var localizerClientResourceMock = new Mock <IClientServiceResources>(); var localizerClientResource = localizerClientResourceMock.Object; IClientService clientService = new ClientService(clientRepository, localizerClientResource); IApiResourceService apiResourceService = new ApiResourceService(apiResourceRepository, localizerApiResource, clientService); //Generate random new api resource var apiResourceDto = ApiResourceDtoMock.GenerateRandomApiResource(0); await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var apiResource = await context.ApiResources.Where(x => x.Name == apiResourceDto.Name).SingleOrDefaultAsync(); var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id); //Assert new api resource apiResourceDto.ShouldBeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id)); //Generate random new api scope var apiScopeDtoMock = ApiResourceDtoMock.GenerateRandomApiScope(0, newApiResourceDto.Id); //Add new api scope await apiResourceService.AddApiScopeAsync(apiScopeDtoMock); //Get inserted api scope var apiScope = await context.ApiScopes.Where(x => x.Name == apiScopeDtoMock.Name && x.ApiResource.Id == newApiResourceDto.Id) .SingleOrDefaultAsync(); //Map entity to model var apiScopesDto = apiScope.ToModel(); //Get new api scope var newApiScope = await apiResourceService.GetApiScopeAsync(apiScopesDto.ApiResourceId, apiScopesDto.ApiScopeId); //Assert newApiScope.ShouldBeEquivalentTo(apiScopesDto, o => o.Excluding(x => x.ResourceName)); } }
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 apiScopes = await clientRepository.GetScopesAsync(apiResource.Name); apiScopes[0].Should().Be(apiResource.Name); } }
public async void ShouldAddAndSaveTheApiResourceInTheContext() { var apiResource = new Models.ApiResource(); var context = A.Fake <IConfigurationDbContext>(); var apiRepository = new ApiResourceRepository(context); await apiRepository.AddAsync(apiResource); A.CallTo(() => context.SaveChangesAsync()) .MustHaveHappened(); A.CallTo(() => context.ApiResources.AddAsync( A <Entities.ApiResource> .Ignored, A <CancellationToken> .Ignored)) .MustHaveHappened(); }
/// <summary> /// Gets all resources. /// </summary> public virtual async Task <IdentityServer4.Models.Resources> GetAllResourcesAsync() { return(await ResourcesCache.GetOrAddAsync(AllResourcesKey, async() => { var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails: true); var apiResources = await ApiResourceRepository.GetListAsync(includeDetails: true); var apiScopes = await ApiScopeRepository.GetListAsync(includeDetails: true); return new Resources( ObjectMapper.Map <List <Volo.Abp.IdentityServer.IdentityResources.IdentityResource>, List <IdentityServer4.Models.IdentityResource> >(identityResources), ObjectMapper.Map <List <Volo.Abp.IdentityServer.ApiResources.ApiResource>, List <IdentityServer4.Models.ApiResource> >(apiResources), ObjectMapper.Map <List <Volo.Abp.IdentityServer.ApiScopes.ApiScope>, List <IdentityServer4.Models.ApiScope> >(apiScopes)); }, () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration })); }
public async Task UpdateApiResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context); IClientRepository clientRepository = new ClientRepository(context); var localizerApiResourceMock = new Mock <IApiResourceServiceResources>(); var localizerApiResource = localizerApiResourceMock.Object; var localizerClientResourceMock = new Mock <IClientServiceResources>(); var localizerClientResource = localizerClientResourceMock.Object; IClientService clientService = new ClientService(clientRepository, localizerClientResource); IApiResourceService apiResourceService = new ApiResourceService(apiResourceRepository, localizerApiResource, clientService); //Generate random new api resource var apiResourceDto = ApiResourceDtoMock.GenerateRandomApiResource(0); await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var apiResource = await context.ApiResources.Where(x => x.Name == apiResourceDto.Name).SingleOrDefaultAsync(); var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id); //Assert new api resource apiResourceDto.Should().BeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(apiResource).State = EntityState.Detached; //Generete new api resuorce with added item id var updatedApiResource = ApiResourceDtoMock.GenerateRandomApiResource(apiResource.Id); //Update api resource await apiResourceService.UpdateApiResourceAsync(updatedApiResource); var updatedApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id); //Assert updated api resuorce updatedApiResource.Should().BeEquivalentTo(updatedApiResourceDto, options => options.Excluding(o => o.Id)); } }
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); } }
public virtual async Task <IEnumerable <ApiResource> > FindApiResourcesByScopeAsync(IEnumerable <string> scopeNames) { var resources = await ApiResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails : true); return(resources.Select(x => ObjectMapper.Map <ApiResources.ApiResource, ApiResource>(x))); }
private IApiResourceRepository <AdminDbContext> GetApiResourceRepository(AdminDbContext context) { IApiResourceRepository <AdminDbContext> apiResourceRepository = new ApiResourceRepository <AdminDbContext>(context); return(apiResourceRepository); }
public virtual async Task <ApiResource> FindApiResourceAsync(string name) { var resource = await ApiResourceRepository.FindByNameAsync(name); return(ObjectMapper.Map <ApiResources.ApiResource, ApiResource>(resource)); }
/// <summary> /// 查询可用的Api资源 /// </summary> /// <returns></returns> public virtual async Task <ListResultDto <string> > GetAssignableApiResourcesAsync() { var resourceNames = await ApiResourceRepository.GetNamesAsync(); return(new ListResultDto <string>(resourceNames)); }
public SecretUoW(ISessionManager sessionManager, SecretRepository secretRepository, ApiResourceRepository apiResourceRepository) : base(sessionManager) { m_secretRepository = secretRepository; m_apiResourceRepository = apiResourceRepository; }
private IApiResourceRepository GetApiResourceRepository(IdentityServerConfigurationDbContext context) { IApiResourceRepository apiResourceRepository = new ApiResourceRepository <IdentityServerConfigurationDbContext>(context); return(apiResourceRepository); }
public ApiResourceTest() { repository = Startup.ConfigureServices().GetService<ApiResourceRepository>(); }