コード例 #1
0
        public async Task DeleteClientSecretAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                var localizerMock = new Mock <IClientServiceResources>();
                var localizer     = localizerMock.Object;

                IClientService clientService = new ClientService(clientRepository, localizer);

                //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.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id));

                //Generate random new Client secret
                var clientSecret = ClientDtoMock.GenerateRandomClientSecret(0, clientEntity.Id);

                //Add new client secret
                await clientService.AddClientSecretAsync(clientSecret);

                //Get inserted client secret
                var secret = await context.ClientSecrets.Where(x => x.Value == clientSecret.Value && x.Client.Id == clientEntity.Id)
                             .SingleOrDefaultAsync();

                //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 context.ClientSecrets.Where(x => x.Id == secret.Id).SingleOrDefaultAsync();

                //Assert after delete it
                deleteClientSecret.Should().BeNull();
            }
        }
コード例 #2
0
        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();
        }