public async Task DeleteApiScopeAsync() { 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 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(); } }
public async Task GetApiScopeAsync() { 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 apiResourceRepository.GetApiScopeAsync(apiResource.Id, apiScope.Id); //Assert new api resource newApiScopes.ShouldBeEquivalentTo(apiScope, options => options.Excluding(o => o.Id)); } }
public async Task UpdateApiScopeAsync() { 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; //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); } }
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); } }