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)); } }
public async Task UpdateApiResourceAsync() { 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; //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 GetApiResourceAsync() { 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); //Get new api resource var newApiResource = await apiResourceRepository.GetApiResourceAsync(apiResource.Id); //Assert new api resource newApiResource.Should().BeEquivalentTo(apiResource, options => options.Excluding(o => o.Id).Excluding(o => o.Secrets) .Excluding(o => o.Scopes) .Excluding(o => o.UserClaims)); newApiResource.UserClaims.Should().BeEquivalentTo(apiResource.UserClaims, option => option.Excluding(x => x.Path.EndsWith("Id")) .Excluding(x => x.Path.EndsWith("ApiResource"))); } }
public async Task UpdateApiResourceAsync() { 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"))); //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 apiResourceRepository.GetApiResourceAsync(updatedApiResource.Id); //Assert updated api resource updatedApiResource.ShouldBeEquivalentTo(updatedApiResourceEntity, options => options.Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "UserClaims\\[.+\\].Id"))); }
public async Task AddApiScopeAsync() { 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 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 DeleteApiSecretAsync() { 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 apiSecret = ApiResourceMock.GenerateRandomApiSecret(); //Add new api secret var apiSecretId = await apiResourceRepository.AddApiSecretAsync(apiResourceId, apiSecret); //Get new api resource var newApiSecret = await apiResourceRepository.GetApiSecretAsync(apiSecretId); //Assert new api resource newApiSecret.ShouldBeEquivalentTo(apiSecret, options => options.Excluding(o => o.Id).Excluding(x => x.ApiResource).Excluding(x => x.Expiration)); //Try delete it await apiResourceRepository.DeleteApiSecretAsync(newApiSecret); //Get deleted api secret var deletedApiSecret = await apiResourceRepository.GetApiSecretAsync(newApiSecret.Id); //Assert if it exist deletedApiSecret.Should().BeNull(); }
public async Task DeleteApiResourceAsync() { 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"))); //Delete api resource await apiResourceRepository.DeleteApiResourceAsync(newApiResource); //Get deleted api resource var deletedApiResource = await apiResourceRepository.GetApiResourceAsync(apiResourceId); //Assert if it not exist deletedApiResource.Should().BeNull(); }
public async Task DeleteApiResourceAsync() { 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).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 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 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 void CanMapApiResourceToModel() { //Generate entity var apiResource = ApiResourceMock.GenerateRandomApiResource(1); //Try map to DTO var apiResourceDto = apiResource.ToModel(); //Assert apiResourceDto.Should().NotBeNull(); apiResource.ShouldBeEquivalentTo(apiResourceDto, options => options.Excluding(o => o.Secrets) .Excluding(o => o.Scopes) .Excluding(o => o.Properties) .Excluding(o => o.Created) .Excluding(o => o.Updated) .Excluding(o => o.LastAccessed) .Excluding(o => o.NonEditable) .Excluding(o => o.AllowedAccessTokenSigningAlgorithms) .Excluding(o => o.UserClaims)); //Assert collection apiResource.UserClaims.Select(x => x.Type).ShouldBeEquivalentTo(apiResourceDto.UserClaims); var allowedAlgList = AllowedSigningAlgorithmsConverter.Converter.Convert(apiResource.AllowedAccessTokenSigningAlgorithms, null); allowedAlgList.ShouldBeEquivalentTo(apiResourceDto.AllowedAccessTokenSigningAlgorithms); }
public async Task GetApiResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceRepository = GetApiResourceRepository(context); //Generate random new api resource without id var apiResource = ApiResourceMock.GenerateRandomApiResource(0); //Add new api resource await apiResourceRepository.AddApiResourceAsync(apiResource); //Get new api resource var resource = await apiResourceRepository.GetApiResourceAsync(apiResource.Id); //Assert new api resource resource.Should().BeEquivalentTo(apiResource, options => options.Excluding(o => o.Id)); //Generate random new api resource property var apiResourceProperty = ApiResourceMock.GenerateRandomApiResourceProperty(0); //Add new api resource property await apiResourceRepository.AddApiResourcePropertyAsync(resource.Id, apiResourceProperty); //Get new api resource property var resourceProperty = await apiResourceRepository.GetApiResourcePropertyAsync(apiResourceProperty.Id); resourceProperty.Should().BeEquivalentTo(apiResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.ApiResource)); } }
public async Task AddApiResourcePropertyAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { var apiResourceRepository = GetApiResourceRepository(context); //Generate random new api resource without id var apiResource = ApiResourceMock.GenerateRandomApiResource(0); //Add new api resource await apiResourceRepository.AddApiResourceAsync(apiResource); //Get new api resource var resource = await apiResourceRepository.GetApiResourceAsync(apiResource.Id); //Assert new api resource resource.ShouldBeEquivalentTo(apiResource, options => options.Excluding(o => o.Id)); //Generate random new api resource property var apiResourceProperty = ApiResourceMock.GenerateRandomApiResourceProperty(0); //Add new api resource property await apiResourceRepository.AddApiResourcePropertyAsync(resource.Id, apiResourceProperty); //Get new api resource property var resourceProperty = await context.ApiResourceProperties.Where(x => x.Id == apiResourceProperty.Id) .SingleOrDefaultAsync(); resourceProperty.ShouldBeEquivalentTo(apiResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.ApiResource)); } }
public async Task GetApiSecretAsync() { 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 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.Should().BeEquivalentTo(apiSecret, options => options.Excluding(o => o.Id) .Excluding(o => o.ApiResource.Secrets) .Excluding(o => o.ApiResource.UserClaims) .Excluding(o => o.ApiResource.Scopes)); } }
public async Task DeleteApiSecretAsync() { 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 apiSecret = ApiResourceMock.GenerateRandomApiSecret(0); //Add new api secret await apiResourceRepository.AddApiSecretAsync(apiResource.Id, apiSecret); //Get new api resource var newApiSecret = await context.ApiSecrets.Where(x => x.Id == apiSecret.Id).SingleOrDefaultAsync(); //Assert new api resource newApiSecret.Should().BeEquivalentTo(apiSecret, options => options.Excluding(o => o.Id)); //Try delete it await apiResourceRepository.DeleteApiSecretAsync(newApiSecret); //Get deleted api secret var deletedApiSecret = await context.ApiSecrets.Where(x => x.Id == newApiSecret.Id).SingleOrDefaultAsync(); //Assert if it exist deletedApiSecret.Should().BeNull(); } }
public async Task GetScopesApiResourceAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration); var apiResource = ApiResourceMock.GenerateRandomApiResource(); await apiResourceRepository.AddApiResourceAsync(apiResource); var apiScopes = await clientRepository.GetScopesAsync(apiResource.Name); apiScopes[0].Should().Be(apiResource.Name); }
public async Task DeleteApiResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceRepository = GetApiResourceRepository(context); //Generate random new api resource without id var apiResource = ApiResourceMock.GenerateRandomApiResource(0); //Add new api resource await apiResourceRepository.AddApiResourceAsync(apiResource); //Get new api resource var resource = await apiResourceRepository.GetApiResourceAsync(apiResource.Id); //Assert new api resource resource.Should().BeEquivalentTo(apiResource, options => options.Excluding(o => o.Id) .Excluding(o => o.Secrets) .Excluding(o => o.Scopes) .Excluding(o => o.UserClaims)); resource.UserClaims.Should().BeEquivalentTo(apiResource.UserClaims, option => option.Excluding(x => x.Path.EndsWith("Id")) .Excluding(x => x.Path.EndsWith("ApiResource"))); //Generate random new api resource property var apiResourceProperty = ApiResourceMock.GenerateRandomApiResourceProperty(0); //Add new api resource property await apiResourceRepository.AddApiResourcePropertyAsync(resource.Id, apiResourceProperty); //Get new api resource property var property = await context.ApiResourceProperties.Where(x => x.Id == apiResourceProperty.Id) .SingleOrDefaultAsync(); //Assert property.Should().BeEquivalentTo(apiResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.ApiResource)); //Try delete it await apiResourceRepository.DeleteApiResourcePropertyAsync(property); //Get new api resource property var resourceProperty = await context.ApiResourceProperties.Where(x => x.Id == apiResourceProperty.Id) .SingleOrDefaultAsync(); //Assert resourceProperty.Should().BeNull(); } }
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 void CanMapApiSecretToModel() { //Generate entity var apiSecret = ApiResourceMock.GenerateRandomApiSecret(1); //Try map to DTO var apiSecretsDto = apiSecret.ToModel(); //Assert apiSecretsDto.Should().NotBeNull(); apiSecret.Should().BeEquivalentTo(apiSecretsDto); apiSecret.Id.Should().Be(apiSecretsDto.ApiSecretId); }
public void CanMapApiScopeToModel() { //Generate entity var apiResource = ApiResourceMock.GenerateRandomApiResource(1); //Try map to DTO var apiResourceDto = apiResource.ToModel(); //Asert apiResourceDto.Should().NotBeNull(); apiResource.Should().BeEquivalentTo(apiResourceDto, options => options.Excluding(o => o.UserClaims)); //Assert collection apiResource.UserClaims.Select(x => x.Type).Should().BeEquivalentTo(apiResourceDto.UserClaims); }
public void CanMapApiSecretToModel() { //Generate entity var apiSecret = ApiResourceMock.GenerateRandomApiSecret(1); //Try map to DTO var apiSecretsDto = apiSecret.ToModel(); //Assert apiSecretsDto.Should().NotBeNull(); apiSecret.ShouldBeEquivalentTo(apiSecretsDto, options => options.Excluding(o => o.ApiResource) .Excluding(o => o.Created) .Excluding(o => o.Id)); apiSecret.Id.Should().Be(apiSecretsDto.ApiSecretId); }
public async Task AddApiResourceAsync() { 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); //Get new api resource var newApiResource = await context.ApiResources.Where(x => x.Id == apiResource.Id).SingleAsync(); //Assert new api resource newApiResource.Should().BeEquivalentTo(apiResource, 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 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); } }
public async Task GetApiResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceRepository = GetApiResourceRepository(context); //Generate random new api resource without id var apiResource = ApiResourceMock.GenerateRandomApiResource(0); //Add new api resource await apiResourceRepository.AddApiResourceAsync(apiResource); //Get new api resource var resource = await apiResourceRepository.GetApiResourceAsync(apiResource.Id); //Assert new api resource resource.ShouldBeEquivalentTo(apiResource, options => options.Excluding(o => o.Id) .Excluding(o => o.Secrets) .Excluding(o => o.Scopes) .Excluding(o => o.UserClaims)); resource.UserClaims.ShouldBeEquivalentTo(apiResource.UserClaims, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("ApiResource"))); //Generate random new api resource property var apiResourceProperty = ApiResourceMock.GenerateRandomApiResourceProperty(0); //Add new api resource property await apiResourceRepository.AddApiResourcePropertyAsync(resource.Id, apiResourceProperty); //Get new api resource property var resourceProperty = await apiResourceRepository.GetApiResourcePropertyAsync(apiResourceProperty.Id); resourceProperty.ShouldBeEquivalentTo(apiResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.ApiResource)); } }
public void CanMapApiScopeToModel() { //Generate entity var apiResource = ApiResourceMock.GenerateRandomApiResource(1); //Try map to DTO var apiResourceDto = apiResource.ToModel(); //Asert apiResourceDto.Should().NotBeNull(); apiResource.ShouldBeEquivalentTo(apiResourceDto, options => options.Excluding(o => o.Secrets) .Excluding(o => o.Scopes) .Excluding(o => o.Properties) .Excluding(o => o.Created) .Excluding(o => o.Updated) .Excluding(o => o.LastAccessed) .Excluding(o => o.NonEditable) .Excluding(o => o.UserClaims)); //Assert collection apiResource.UserClaims.Select(x => x.Type).ShouldBeEquivalentTo(apiResourceDto.UserClaims); }
public void CanMapApiSecretToModel() { //Generate entity var apiSecret = ApiResourceMock.GenerateRandomApiSecret(1); //Try map to DTO var apiSecretDto = apiSecret.ToModel(); //Assert apiSecretDto.Should().NotBeNull(); apiSecret.Should().BeEquivalentTo(apiSecretDto, options => options.Excluding(o => o.Created) .Excluding(o => o.ApiSecretId) .Excluding(o => o.ApiResourceName) .Excluding(o => o.TypeList) .Excluding(o => o.HashType) .Excluding(o => o.HashTypes) .Excluding(o => o.ApiResourceSecrets) .Excluding(o => o.TotalCount) .Excluding(o => o.PageSize)); apiSecret.Id.Should().Be(apiSecretDto.ApiSecretId); }
public async Task GetApiScopeAsync() { 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 scope var apiScopeId = await apiResourceRepository.AddApiScopeAsync(apiResourceId, apiScope); //Get new api scope 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"))); }