Example #1
0
        public async Task GetApiResourceAsync()
        {
            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));
            }
        }
Example #2
0
        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();
        }
Example #3
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();
            }
        }
Example #4
0
        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));
        }
Example #5
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();
        }
Example #6
0
        public async Task GetApiScopeAsync()
        {
            using (var context = new ConfigurationDbContext(_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 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));
            }
        }
Example #7
0
        public async Task UpdateApiResourceAsync()
        {
            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.Should().BeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(apiResource).State = EntityState.Detached;

                //Generete new api resuorce with added item id
                var updatedApiResource = ApiResourceDtoMock.GenerateRandomApiResource(apiResource.Id);

                //Update api resource
                await apiResourceService.UpdateApiResourceAsync(updatedApiResource);

                var updatedApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id);

                //Assert updated api resuorce
                updatedApiResource.Should().BeEquivalentTo(updatedApiResourceDto, options => options.Excluding(o => o.Id));
            }
        }
Example #8
0
        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));
        }
Example #9
0
        private IApiResourceService GetApiResourceService(IApiResourceRepository repository, IApiResourceServiceResources resources, IClientService clientService, IAuditEventLogger auditEventLogger)
        {
            IApiResourceService apiResourceService = new ApiResourceService(repository, resources, clientService, auditEventLogger);

            return(apiResourceService);
        }
 public ApiResourceController(ApiResourceService identityResourceService)
 {
     _apiResourceService = identityResourceService;
 }
        private IApiResourceService GetApiResourceService(IApiResourceRepository repository, IApiResourceServiceResources resources, IClientService clientService)
        {
            IApiResourceService apiResourceService = new ApiResourceService(repository, resources, clientService);

            return(apiResourceService);
        }
 public ApiResourceController(ApiResourceService service)
 {
     this.service = service;
 }
        private IApiResourceService <AdminDbContext> GetApiResourceService(IApiResourceRepository <AdminDbContext> repository, IApiResourceServiceResources resources, IClientService <AdminDbContext> clientService)
        {
            IApiResourceService <AdminDbContext> apiResourceService = new ApiResourceService <AdminDbContext>(repository, resources, clientService);

            return(apiResourceService);
        }