private IApiResourceService GetApiResourceService(IdentityServerConfigurationDbContext context) { var apiResourceRepository = GetApiResourceRepository(context); var clientRepository = GetClientRepository(context); var localizerApiResourceMock = new Mock <IApiResourceServiceResources>(); var localizerApiResource = localizerApiResourceMock.Object; var localizerClientResourceMock = new Mock <IClientServiceResources>(); var localizerClientResource = localizerClientResourceMock.Object; var auditLoggerMock = new Mock <IAuditEventLogger>(); var auditLogger = auditLoggerMock.Object; var clientService = GetClientService(clientRepository, localizerClientResource, auditLogger); var apiResourceService = GetApiResourceService(apiResourceRepository, localizerApiResource, clientService, auditLogger); return(apiResourceService); }
public async Task DeleteClientPropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientRepository = GetClientRepository(context); //Generate random new client without id var client = ClientMock.GenerateRandomClient(0); //Add new client await clientRepository.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(client.Id); //Assert new client ClientAssert(clientEntity, client); //Generate random new Client Property var clientProperty = ClientMock.GenerateRandomClientProperty(0); //Add new client property await clientRepository.AddClientPropertyAsync(clientEntity.Id, clientProperty); //Get new client property var newClientProperties = await context.ClientProperties.Where(x => x.Id == clientProperty.Id) .SingleOrDefaultAsync(); //Assert newClientProperties.Should().BeEquivalentTo(clientProperty, options => options.Excluding(o => o.Id).Excluding(x => x.Client)); //Try delete it await clientRepository.DeleteClientPropertyAsync(newClientProperties); //Get new client property var deletedClientProperty = await context.ClientProperties.Where(x => x.Id == clientProperty.Id) .SingleOrDefaultAsync(); //Assert deletedClientProperty.Should().BeNull(); } }
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 async Task GetClientAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientRepository = GetClientRepository(context); //Generate random new client without id var client = ClientMock.GenerateRandomClient(0); //Add new client await clientRepository.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(client.Id); //Assert new client ClientAssert(clientEntity, client); } }
public async Task AddIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleAsync(); //Assert new identity resource newIdentityResource.Should().BeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); } }
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)); } }
public async Task UpdateApiScopeAsync() { 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).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 DeleteIdentityResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource without id var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource resource.Should().BeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Generate random new identity resource property var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0); //Add new identity resource property await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty); //Get new identity resource property var property = await context.IdentityResourceProperties.Where(x => x.Id == identityResourceProperty.Id) .SingleOrDefaultAsync(); //Assert property.Should().BeEquivalentTo(identityResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource)); //Try delete it await identityResourceRepository.DeleteIdentityResourcePropertyAsync(property); //Get new identity resource property var resourceProperty = await context.IdentityResourceProperties.Where(x => x.Id == identityResourceProperty.Id) .SingleOrDefaultAsync(); //Assert resourceProperty.Should().BeNull(); } }
public async Task AddClientAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientRepository = GetClientRepository(context); //Generate random new client var client = ClientMock.GenerateRandomClient(0); //Add new client await clientRepository.AddClientAsync(client); //Get new client var clientEntity = await context.Clients.Where(x => x.Id == client.Id).SingleAsync(); //Assert new client clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id)); } }
public async Task AddApiSecretAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceService = GetApiResourceService(context); //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)); //Generate random new api secret var apiSecretsDto = ApiResourceDtoMock.GenerateRandomApiSecret(0, newApiResourceDto.Id); //Add new api secret await apiResourceService.AddApiSecretAsync(apiSecretsDto); //Get inserted api secret var apiSecret = await context.ApiSecrets.Where(x => x.Value == apiSecretsDto.Value && x.ApiResource.Id == newApiResourceDto.Id) .SingleOrDefaultAsync(); //Map entity to model var secretsDto = apiSecret.ToModel(); //Get new api secret var newApiSecret = await apiResourceService.GetApiSecretAsync(secretsDto.ApiSecretId); //Assert secret value secretsDto.Value.Should().Be(apiSecretsDto.Value); //Assert newApiSecret.Should().BeEquivalentTo(secretsDto, o => o.Excluding(x => x.ApiResourceName).Excluding(x => x.Value)); } }
public async Task AddClientPropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientService = GetClientService(context); //Generate random new client var client = ClientDtoMock.GenerateRandomClient(0); await clientService.AddClientAsync(client); //Get new client var clientEntity = await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync(); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.Should().BeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); //Generate random new Client property var clicentProperty = ClientDtoMock.GenerateRandomClientProperty(0, clientEntity.Id); //Add new client property await clientService.AddClientPropertyAsync(clicentProperty); //Get inserted client property var property = await context.ClientProperties.Where(x => x.Value == clicentProperty.Value && x.Client.Id == clientEntity.Id) .SingleOrDefaultAsync(); //Map entity to model var propertyDto = property.ToModel(); //Get new client property var clientPropertiesDto = await clientService.GetClientPropertyAsync(property.Id); //Assert clientPropertiesDto.Should().BeEquivalentTo(propertyDto, options => options.Excluding(o => o.ClientPropertyId) .Excluding(o => o.ClientName)); } }
public async Task AddApiResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceService = GetApiResourceService(context); //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)); } }
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.Should().BeEquivalentTo(apiResource, options => options.Excluding(o => o.Id) .Excluding(o => o.Secrets) .Excluding(o => o.Scopes) .Excluding(o => o.Properties) .Excluding(o => o.UserClaims)); resource.UserClaims.Should().BeEquivalentTo(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.Should().BeEquivalentTo(apiResourceProperty, options => options.Excluding(o => o.Id) .Excluding(x => x.ApiResource)); } }
public async Task GetApiResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceService = GetApiResourceService(context); //Generate random new api resource var apiResource = ApiResourceDtoMock.GenerateRandomApiResource(0); await apiResourceService.AddApiResourceAsync(apiResource); //Get new api resource var resource = await context.ApiResources.Where(x => x.Name == apiResource.Name).SingleOrDefaultAsync(); var apiResourceDto = await apiResourceService.GetApiResourceAsync(resource.Id); //Assert new api resource apiResource.Should().BeEquivalentTo(apiResourceDto, options => options.Excluding(o => o.Id)); //Generate random new api resource property var apiResourceProperty = ApiResourceDtoMock.GenerateRandomApiResourceProperty(0, resource.Id); //Add new api resource property await apiResourceService.AddApiResourcePropertyAsync(apiResourceProperty); //Get inserted api resource property var property = await context.ApiResourceProperties.Where(x => x.Value == apiResourceProperty.Value && x.ApiResource.Id == resource.Id) .SingleOrDefaultAsync(); //Map entity to model var propertyDto = property.ToModel(); //Get new api resource property var apiResourcePropertiesDto = await apiResourceService.GetApiResourcePropertyAsync(property.Id); //Assert apiResourcePropertiesDto.Should().BeEquivalentTo(propertyDto, options => options.Excluding(o => o.ApiResourcePropertyId) .Excluding(o => o.ApiResourceName)); } }
public async Task AddClientAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientService = GetClientService(context); //Generate random new client var client = ClientDtoMock.GenerateRandomClient(0); await clientService.AddClientAsync(client); //Get new client var clientEntity = await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync(); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.Should().BeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); } }
public async Task RemoveApiResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceRepository = GetApiResourceRepository(context); var clientRepository = GetClientRepository(context); var localizerApiResourceMock = new Mock <IApiResourceServiceResources>(); var localizerApiResource = localizerApiResourceMock.Object; var localizerClientResourceMock = new Mock <IClientServiceResources>(); var localizerClientResource = localizerClientResourceMock.Object; var clientService = GetClientService(clientRepository, localizerClientResource); var apiResourceService = GetApiResourceService(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)); //Remove api resource await apiResourceService.DeleteApiResourceAsync(newApiResourceDto); //Try get removed api resource var removeApiResource = await context.ApiResources.Where(x => x.Id == apiResource.Id) .SingleOrDefaultAsync(); //Assert removed api resource removeApiResource.Should().BeNull(); } }
public async Task RemoveClientAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientRepository = GetClientRepository(context); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; var clientService = GetClientService(clientRepository, localizer); //Generate random new client without id var client = ClientDtoMock.GenerateRandomClient(0); //Add new client await clientService.AddClientAsync(client); //Get new client var clientEntity = await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync(); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.Should().BeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(clientEntity).State = EntityState.Detached; //Remove client await clientService.RemoveClientAsync(clientDto); //Try Get Removed client var removeClientEntity = await context.Clients.Where(x => x.Id == clientEntity.Id) .SingleOrDefaultAsync(); //Assert removed client - it might be null removeClientEntity.Should().BeNull(); } }
public async Task UpdateIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; var identityResourceService = GetIdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.Should().BeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(identityResource).State = EntityState.Detached; //Generete new identity resuorce with added item id var updatedIdentityResource = IdentityResourceDtoMock.GenerateRandomIdentityResource(identityResource.Id); //Update identity resuorce await identityResourceService.UpdateIdentityResourceAsync(updatedIdentityResource); var updatedIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert updated identity resuorce updatedIdentityResource.Should().BeEquivalentTo(updatedIdentityResourceDto, options => options.Excluding(o => o.Id)); } }
public async Task UpdateClientAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientService = GetClientService(context); //Generate random new client without id var client = ClientDtoMock.GenerateRandomClient(0); //Add new client await clientService.AddClientAsync(client); //Get new client var clientEntity = await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync(); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.Should().BeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(clientEntity).State = EntityState.Detached; //Generete new client with added item id var updatedClient = ClientDtoMock.GenerateRandomClient(clientDto.Id); //Update client await clientService.UpdateClientAsync(updatedClient); //Get updated client var updatedClientEntity = await context.Clients.Where(x => x.Id == updatedClient.Id).SingleAsync(); var updatedClientDto = await clientService.GetClientAsync(updatedClientEntity.Id); //Assert updated client updatedClient.Should().BeEquivalentTo(updatedClientDto, options => options.Excluding(o => o.Id)); } }
public async Task GetApiScopeAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiResourceService = GetApiResourceService(context); //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 UpdateApiScopeAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var apiScopeService = GetApiScopeService(context); //Generate random new api scope var apiScopeDtoMock = ApiScopeDtoMock.GenerateRandomApiScope(0); //Add new api scope await apiScopeService.AddApiScopeAsync(apiScopeDtoMock); //Get inserted api scope var apiScope = await context.ApiScopes.Where(x => x.Name == apiScopeDtoMock.Name) .SingleOrDefaultAsync(); //Map entity to model var apiScopesDto = apiScope.ToModel(); //Get new api scope var newApiScope = await apiScopeService.GetApiScopeAsync(apiScopesDto.Id); //Assert newApiScope.ShouldBeEquivalentTo(apiScopesDto); //Detached the added item context.Entry(apiScope).State = EntityState.Detached; //Update api scope var updatedApiScope = ApiScopeDtoMock.GenerateRandomApiScope(apiScopesDto.Id); await apiScopeService.UpdateApiScopeAsync(updatedApiScope); var updatedApiScopeDto = await apiScopeService.GetApiScopeAsync(apiScopesDto.Id); //Assert updated api scope updatedApiScope.ShouldBeEquivalentTo(updatedApiScopeDto); } }
public async Task GetIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id).Excluding(o => o.UserClaims)); newIdentityResource.UserClaims.ShouldBeEquivalentTo(identityResource.UserClaims, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("IdentityResource"))); } }
public async Task AddIdentityResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource without id var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource resource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id) .Excluding(o => o.UserClaims)); resource.UserClaims.ShouldBeEquivalentTo(identityResource.UserClaims, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("IdentityResource"))); //Generate random new identity resource property var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0); //Add new identity resource property await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty); //Get new identity resource property var resourceProperty = await context.IdentityResourceProperties.Where(x => x.Id == identityResourceProperty.Id) .SingleOrDefaultAsync(); resourceProperty.ShouldBeEquivalentTo(identityResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource)); } }
public async Task CloneClientWithoutScopesAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { //Generate random new client var client = ClientMock.GenerateRandomClient(0, generateClaims: true, generateProperties: true, generateSecrets: false); var clientRepository = GetClientRepository(context); //Add new client await clientRepository.AddClientAsync(client); var clientToClone = await context.Clients.Where(x => x.Id == client.Id).SingleOrDefaultAsync(); //Try clone it var clonedClientId = await clientRepository.CloneClientAsync(clientToClone, cloneClientScopes : false); var cloneClientEntity = await clientRepository.GetClientAsync(clonedClientId); var clientToCompare = await clientRepository.GetClientAsync(clientToClone.Id); ClientCloneCompare(cloneClientEntity, clientToCompare, cloneClientScopes: false); } }
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"))); } }
private IIdentityResourceRepository GetIdentityResourceRepository(IdentityServerConfigurationDbContext context) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository <IdentityServerConfigurationDbContext>(context); return(identityResourceRepository); }
private IApiScopeRepository GetApiScopeRepository(IdentityServerConfigurationDbContext context) { IApiScopeRepository apiScopeRepository = new ApiScopeRepository <IdentityServerConfigurationDbContext>(context); return(apiScopeRepository); }
private IClientRepository GetClientRepository(IdentityServerConfigurationDbContext context) { IClientRepository clientRepository = new ClientRepository <IdentityServerConfigurationDbContext>(context); return(clientRepository); }
public async Task CloneClientAsync() { int clonedClientId; using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { //Generate random new client var clientDto = ClientDtoMock.GenerateRandomClient(0); var clientRepository = GetClientRepository(context); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; var clientService = GetClientService(clientRepository, localizer); //Add new client await clientService.AddClientAsync(clientDto); var clientId = await context.Clients.Where(x => x.ClientId == clientDto.ClientId).Select(x => x.Id) .SingleOrDefaultAsync(); var clientDtoToClone = await clientService.GetClientAsync(clientId); var clientCloneDto = ClientDtoMock.GenerateClientCloneDto(clientDtoToClone.Id); //Try clone it clonedClientId = await clientService.CloneClientAsync(clientCloneDto); var cloneClientEntity = await context.Clients .Include(x => x.AllowedGrantTypes) .Include(x => x.RedirectUris) .Include(x => x.PostLogoutRedirectUris) .Include(x => x.AllowedScopes) .Include(x => x.ClientSecrets) .Include(x => x.Claims) .Include(x => x.IdentityProviderRestrictions) .Include(x => x.AllowedCorsOrigins) .Include(x => x.Properties) .Where(x => x.Id == clonedClientId).SingleOrDefaultAsync(); var clientToCompare = await context.Clients .Include(x => x.AllowedGrantTypes) .Include(x => x.RedirectUris) .Include(x => x.PostLogoutRedirectUris) .Include(x => x.AllowedScopes) .Include(x => x.ClientSecrets) .Include(x => x.Claims) .Include(x => x.IdentityProviderRestrictions) .Include(x => x.AllowedCorsOrigins) .Include(x => x.Properties) .Where(x => x.Id == clientDtoToClone.Id).SingleOrDefaultAsync(); //Assert cloned client cloneClientEntity.Should().BeEquivalentTo(clientToCompare, options => options.Excluding(o => o.Id) .Excluding(o => o.ClientSecrets) .Excluding(o => o.ClientId) .Excluding(o => o.ClientName) //Skip the collections because is not possible ignore property in list :-( //Note: I've found the solution above - try ignore property of the list using SelectedMemberPath .Excluding(o => o.AllowedGrantTypes) .Excluding(o => o.RedirectUris) .Excluding(o => o.PostLogoutRedirectUris) .Excluding(o => o.AllowedScopes) .Excluding(o => o.ClientSecrets) .Excluding(o => o.Claims) .Excluding(o => o.IdentityProviderRestrictions) .Excluding(o => o.AllowedCorsOrigins) .Excluding(o => o.Properties) ); //New client relations have new id's and client relations therefore is required ignore them cloneClientEntity.AllowedGrantTypes.Should().BeEquivalentTo(clientToCompare.AllowedGrantTypes, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.AllowedCorsOrigins.Should().BeEquivalentTo(clientToCompare.AllowedCorsOrigins, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.RedirectUris.Should().BeEquivalentTo(clientToCompare.RedirectUris, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.PostLogoutRedirectUris.Should().BeEquivalentTo(clientToCompare.PostLogoutRedirectUris, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.AllowedScopes.Should().BeEquivalentTo(clientToCompare.AllowedScopes, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.ClientSecrets.Should().BeEquivalentTo(clientToCompare.ClientSecrets, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.Claims.Should().BeEquivalentTo(clientToCompare.Claims, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.IdentityProviderRestrictions.Should().BeEquivalentTo( clientToCompare.IdentityProviderRestrictions, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); cloneClientEntity.Properties.Should().BeEquivalentTo(clientToCompare.Properties, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("Client"))); } }