Esempio n. 1
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();
        }
Esempio n. 2
0
        public async Task RemoveApiResourceAsync()
        {
            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));

                //Remove api resource
                await apiResourceService.DeleteApiResourceAsync(newApiResourceDto);

                //Try get removed api resource
                var removeApiResource = await context.ApiResources.Where(x => x.Id == apiResource.Id)
                                        .SingleOrDefaultAsync();

                //Assert removed api resource
                removeApiResource.Should().BeNull();
            }
        }