Esempio n. 1
0
        public async Task DeleteApiSecretAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context);
                IClientRepository      clientRepository      = new ClientRepository(context);

                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);

                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 secret
                var apiSecretsDtoMock = ApiResourceDtoMock.GenerateRandomApiSecret(0, newApiResourceDto.Id);

                //Add new api secret
                await apiResourceService.AddApiSecretAsync(apiSecretsDtoMock);

                //Get inserted api secret
                var apiSecret = await context.ApiSecrets.Where(x => x.Value == apiSecretsDtoMock.Value && x.ApiResource.Id == newApiResourceDto.Id)
                                .SingleOrDefaultAsync();

                //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 context.ApiSecrets.Where(x => x.Value == apiSecretsDtoMock.Value && x.ApiResource.Id == newApiResourceDto.Id)
                                       .SingleOrDefaultAsync();

                //Assert after deleting
                deletedApiSecret.Should().BeNull();
            }
        }
Esempio n. 2
0
        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();
        }