public async Task RemoveClientAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; IClientService clientService = new ClientService(clientRepository, localizer); //Generate random new client without id var client = ClientDtoMock.GenerateRandomClient(0); //Add new client var clientId = await clientService.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); //Remove client await clientService.RemoveClientAsync(clientDto); //Try Get Removed client var removeClientEntity = await clientRepository.GetClientAsync(clientEntity.Id); //Assert removed client - it might be null removeClientEntity.Should().BeNull(); }
public async Task RemoveApiResourceAsync() { IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration); IClientRepository clientRepository = new ClientDapperRepository(_configuration); 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); var apiResourceDtoId = await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResourceDtoId); //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 apiResourceRepository.GetApiResourceAsync(apiResourceDtoId); //Assert removed api resource removeApiResource.Should().BeNull(); }
public async Task RemoveClientAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); //Generate random new client without id var client = ClientMock.GenerateRandomClient(); //Add new client var clientId = await clientRepository.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); //Assert new client clientEntity.ShouldBeEquivalentTo(client, options => options.Excluding(o => o.Id) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Id"))); //Remove client await clientRepository.RemoveClientAsync(clientEntity); //Try Get Removed client var removeClientEntity = await clientRepository.GetClientAsync(clientId); //Assert removed client - it might be null removeClientEntity.Should().BeNull(); }
public async Task AddClientPropertyAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); //Generate random new client without id var client = ClientMock.GenerateRandomClient(); //Add new client var clientId = await clientRepository.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); //Assert new client clientEntity.ShouldBeEquivalentTo(client, options => options.Excluding(o => o.Id) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Id"))); //Generate random new Client property var clientProperty = ClientMock.GenerateRandomClientProperty(); //Add new client property var clientPropertyId = await clientRepository.AddClientPropertyAsync(clientEntity.Id, clientProperty); //Get new client property var newClientProperty = await clientRepository.GetClientPropertyAsync(clientPropertyId); newClientProperty.ShouldBeEquivalentTo(clientProperty, options => options.Excluding(o => o.Id).Excluding(x => x.Client)); }
public async Task CloneClientAsync() { int clonedClientId; //Generate random new client var clientDto = ClientDtoMock.GenerateRandomClient(0); IClientRepository clientRepository = new ClientDapperRepository(_configuration); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; IClientService clientService = new ClientService(clientRepository, localizer); //Add new client var clientId = await clientService.AddClientAsync(clientDto); var clientDtoToClone = await clientService.GetClientAsync(clientId); var clientCloneDto = ClientDtoMock.GenerateClientCloneDto(clientDtoToClone); //Try clone it clonedClientId = await clientService.CloneClientAsync(clientCloneDto); var cloneClientEntity = await clientRepository.GetClientAsync(clonedClientId); //Assert cloned client cloneClientEntity.ShouldBeEquivalentTo(clientDtoToClone, options => options.Excluding(o => o.Id) .Excluding(o => o.ClientSecrets) .Excluding(o => o.ClientId) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].GrantType")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Client")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].RedirectUri")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].Client")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].PostLogoutRedirectUri")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].Client")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Scope")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Client")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Provider")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Client")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "ClientSecrets\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "Claims\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Origin")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Client")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "Properties\\[.+\\].Id"))); }
public void GetStandardClaims() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); //Try get some existing claims var randomClientClaim = ClientMock.GenerateRandomClientClaim(); var grantTypes = clientRepository.GetStandardClaims(randomClientClaim.Type); grantTypes.Contains(randomClientClaim.Type).Should().Be(true); }
public void GetGrantTypes() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); //Try get some existing grant var randomClientGrantType = ClientMock.GenerateRandomClientGrantType(); var grantTypes = clientRepository.GetGrantTypes(randomClientGrantType.GrantType); grantTypes[0].Should().Be(randomClientGrantType.GrantType); }
public async Task UpdateApiScopeAsync() { IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration); IClientRepository clientRepository = new ClientDapperRepository(_configuration); 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); var apiResourceDtoId = await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResourceDtoId); //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 var apiScopeId = await apiResourceService.AddApiScopeAsync(apiScopeDtoMock); //Get inserted api scope var apiScope = await apiResourceRepository.GetApiScopeAsync(apiResourceDtoId, apiScopeId); //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)); //Update api scope var updatedApiScope = ApiResourceDtoMock.GenerateRandomApiScope(apiScopesDto.ApiScopeId, apiScopesDto.ApiResourceId); await apiResourceService.UpdateApiScopeAsync(updatedApiScope); var updatedApiScopeDto = await apiResourceService.GetApiScopeAsync(apiScopesDto.ApiResourceId, apiScopesDto.ApiScopeId); //Assert updated api scope updatedApiScope.ShouldBeEquivalentTo(updatedApiScopeDto, o => o.Excluding(x => x.ResourceName)); }
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 GetScopesIdentityResourceAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); IIdentityResourceRepository identityResourceRepository = new IdentityResourceDapperRepository(_configuration); var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(); await identityResourceRepository.AddIdentityResourceAsync(identityResource); var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name); identityScopes[0].Should().Be(identityResource.Name); }
public async Task DeleteApiSecretAsync() { IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration); IClientRepository clientRepository = new ClientDapperRepository(_configuration); 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); var apiResourceDtoId = await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResourceDtoId); //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 var apiSecretId = await apiResourceService.AddApiSecretAsync(apiSecretsDtoMock); //Get inserted api secret var apiSecret = await apiResourceRepository.GetApiSecretAsync(apiSecretId); //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 apiResourceRepository.GetApiSecretAsync(apiSecretId); //Assert after deleting deletedApiSecret.Should().BeNull(); }
public async Task DeleteClientSecretAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; IClientService clientService = new ClientService(clientRepository, localizer); //Generate random new client var client = ClientDtoMock.GenerateRandomClient(0); var clientId = await clientService.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); //Generate random new Client secret var clientSecret = ClientDtoMock.GenerateRandomClientSecret(0, clientEntity.Id); //Add new client secret var clientSecretId = await clientService.AddClientSecretAsync(clientSecret); //Get inserted client property var secret = await clientRepository.GetClientSecretAsync(clientSecretId); //Map entity to model var secretsDto = secret.ToModel(); //Get new client secret var clientSecretsDto = await clientService.GetClientSecretAsync(secret.Id); //Assert clientSecretsDto.ShouldBeEquivalentTo(secretsDto, options => options.Excluding(o => o.ClientSecretId)); //Delete client secret await clientService.DeleteClientSecretAsync(clientSecretsDto); //Get removed client secret var deleteClientSecret = await clientRepository.GetClientSecretAsync(secret.Id); //Assert after delete it deleteClientSecret.Should().BeNull(); }
public async Task DeleteClientSecretAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); //Generate random new client without id var client = ClientMock.GenerateRandomClient(); //Add new client var clientId = await clientRepository.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); //Assert new client clientEntity.ShouldBeEquivalentTo(client, options => options.Excluding(o => o.Id) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedGrantTypes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "RedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "PostLogoutRedirectUris\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedScopes\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "IdentityProviderRestrictions\\[.+\\].Id")) .Excluding(x => Regex.IsMatch(x.SelectedMemberPath, "AllowedCorsOrigins\\[.+\\].Id"))); //Generate random new Client Secret var clientSecret = ClientMock.GenerateRandomClientSecret(); //Add new client secret var clientSecretId = await clientRepository.AddClientSecretAsync(clientEntity.Id, clientSecret); //Get new client secret var newSecret = await clientRepository.GetClientSecretAsync(clientSecretId); //Asert newSecret.ShouldBeEquivalentTo(clientSecret, options => options.Excluding(o => o.Id).Excluding(x => x.Client).Excluding(x => x.Expiration)); //Try delete it await clientRepository.DeleteClientSecretAsync(newSecret); //Get new client secret var deletedSecret = await clientRepository.GetClientSecretAsync(clientSecret.Id); //Assert deletedSecret.Should().BeNull(); }
public async Task GetClientsAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); var rnd = new Random(); var generateRows = rnd.Next(1, 10); //Generate random new clients var randomClients = ClientMock.GenerateRandomClients(0, generateRows); foreach (var client in randomClients) { await clientRepository.AddClientAsync(client); } var clients = await clientRepository.GetClientsAsync(); //Assert clients count clients.Data.Count.Should().BeGreaterThan(randomClients.Count); }
public async Task GetClientPropertyAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; IClientService clientService = new ClientService(clientRepository, localizer); //Generate random new client var client = ClientDtoMock.GenerateRandomClient(0); var clientId = await clientService.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); //Generate random new Client property var clientProperty = ClientDtoMock.GenerateRandomClientProperty(0, clientEntity.Id); //Add new client property var clientPropertyId = await clientService.AddClientPropertyAsync(clientProperty); //Get inserted client property var property = await clientRepository.GetClientPropertyAsync(clientPropertyId); //Map entity to model var propertyDto = property.ToModel(); //Get new client property var clientPropertiesDto = await clientService.GetClientPropertyAsync(property.Id); //Assert clientPropertiesDto.ShouldBeEquivalentTo(propertyDto, options => options.Excluding(o => o.ClientPropertyId)); }
public async Task CloneClientWithoutScopesAsync() { //Generate random new client var client = ClientMock.GenerateRandomClient(0, generateClaims: true, generateProperties: true, generateSecrets: true); IClientRepository clientRepository = new ClientDapperRepository(_configuration); //Add new client var clientId = await clientRepository.AddClientAsync(client); var clientToClone = await clientRepository.GetClientAsync(clientId); clientToClone.ClientId = $"{clientToClone.ClientId}(Clone))"; //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 AddClientAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); var localizerMock = new Mock <IClientServiceResources>(); var localizer = localizerMock.Object; IClientService clientService = new ClientService(clientRepository, localizer); //Generate random new client var client = ClientDtoMock.GenerateRandomClient(0); var clientId = await clientService.AddClientAsync(client); //Get new client var clientEntity = await clientRepository.GetClientAsync(clientId); var clientDto = await clientService.GetClientAsync(clientEntity.Id); //Assert new client client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id)); }
public async Task UpdateApiResourceAsync() { IApiResourceRepository apiResourceRepository = new ApiResourceDapperRepository(_configuration); IClientRepository clientRepository = new ClientDapperRepository(_configuration); 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); var apiResourceDtoId = await apiResourceService.AddApiResourceAsync(apiResourceDto); //Get new api resource var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResourceDtoId); //Assert new api resource apiResourceDto.ShouldBeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id)); //Generete new api resuorce with added item id var updatedApiResource = ApiResourceDtoMock.GenerateRandomApiResource(newApiResourceDto.Id); //Update api resource await apiResourceService.UpdateApiResourceAsync(updatedApiResource); var updatedApiResourceDto = await apiResourceService.GetApiResourceAsync(newApiResourceDto.Id); //Assert updated api resuorce updatedApiResource.ShouldBeEquivalentTo(updatedApiResourceDto, options => options.Excluding(o => o.Id)); }