public async Task CloneClientAsync() { //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 - all client collections without secrets var clonedClientId = await clientRepository.CloneClientAsync(clientToClone); var cloneClientEntity = await clientRepository.GetClientAsync(clonedClientId); var clientToCompare = await clientRepository.GetClientAsync(clientToClone.Id); ClientCloneCompare(cloneClientEntity, clientToCompare); }
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 DeleteClientClaimAsync() { 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 Claim var clientClaim = ClientMock.GenerateRandomClientClaim(); //Add new client claim var clientClaimId = await clientRepository.AddClientClaimAsync(clientEntity.Id, clientClaim); //Get new client claim var newClientClaim = await clientRepository.GetClientClaimAsync(clientClaimId); //Asert newClientClaim.ShouldBeEquivalentTo(clientClaim, options => options.Excluding(o => o.Id).Excluding(x => x.Client)); //Try delete it await clientRepository.DeleteClientClaimAsync(newClientClaim); //Get new client claim var deletedClientClaim = await clientRepository.GetClientClaimAsync(clientClaimId); //Assert deletedClientClaim.Should().BeNull(); }
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 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)); }