コード例 #1
0
        public async Task DeleteApiResourcePropertyAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceRepository = GetApiResourceRepository(context);
                var clientRepository      = GetClientRepository(context);

                var localizerApiResourceMock = new Mock <IApiResourceServiceResources>();
                var localizerApiResource     = localizerApiResourceMock.Object;

                var localizerClientResourceMock = new Mock <IClientServiceResources>();
                var localizerClientResource     = localizerClientResourceMock.Object;

                var clientService      = GetClientService(clientRepository, localizerClientResource);
                var apiResourceService = GetApiResourceService(apiResourceRepository, localizerApiResource, clientService);

                //Generate random new api resource
                var apiResource = ApiResourceDtoMock.GenerateRandomApiResource(0);

                await apiResourceService.AddApiResourceAsync(apiResource);

                //Get new api resource
                var resource = await context.ApiResources.Where(x => x.Name == apiResource.Name).SingleOrDefaultAsync();

                var apiResourceDto = await apiResourceService.GetApiResourceAsync(resource.Id);

                //Assert new api resource
                apiResource.ShouldBeEquivalentTo(apiResourceDto, options => options.Excluding(o => o.Id));

                //Generate random new api resource Property
                var apiResourcePropertiesDto = ApiResourceDtoMock.GenerateRandomApiResourceProperty(0, resource.Id);

                //Add new api resource Property
                await apiResourceService.AddApiResourcePropertyAsync(apiResourcePropertiesDto);

                //Get inserted api resource Property
                var property = await context.ApiResourceProperties.Where(x => x.Value == apiResourcePropertiesDto.Value && x.ApiResource.Id == resource.Id)
                               .SingleOrDefaultAsync();

                //Map entity to model
                var propertiesDto = property.ToModel();

                //Get new api resource Property
                var resourcePropertiesDto = await apiResourceService.GetApiResourcePropertyAsync(property.Id);

                //Assert
                resourcePropertiesDto.ShouldBeEquivalentTo(propertiesDto, options =>
                                                           options.Excluding(o => o.ApiResourcePropertyId)
                                                           .Excluding(o => o.ApiResourceName));

                //Delete api resource Property
                await apiResourceService.DeleteApiResourcePropertyAsync(resourcePropertiesDto);

                //Get removed api resource Property
                var apiResourceProperty = await context.ApiResourceProperties.Where(x => x.Id == property.Id).SingleOrDefaultAsync();

                //Assert after delete it
                apiResourceProperty.Should().BeNull();
            }
        }
コード例 #2
0
        public async Task GetApiResourcePropertyAsync()
        {
            using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions))
            {
                var apiResourceService = GetApiResourceService(context);

                //Generate random new api resource
                var apiResource = ApiResourceDtoMock.GenerateRandomApiResource(0);

                await apiResourceService.AddApiResourceAsync(apiResource);

                //Get new api resource
                var resource = await context.ApiResources.Where(x => x.Name == apiResource.Name).SingleOrDefaultAsync();

                var apiResourceDto = await apiResourceService.GetApiResourceAsync(resource.Id);

                //Assert new api resource
                apiResource.Should().BeEquivalentTo(apiResourceDto, options => options.Excluding(o => o.Id));

                //Generate random new api resource property
                var apiResourceProperty = ApiResourceDtoMock.GenerateRandomApiResourceProperty(0, resource.Id);

                //Add new api resource property
                await apiResourceService.AddApiResourcePropertyAsync(apiResourceProperty);

                //Get inserted api resource property
                var property = await context.ApiResourceProperties.Where(x => x.Value == apiResourceProperty.Value && x.ApiResource.Id == resource.Id)
                               .SingleOrDefaultAsync();

                //Map entity to model
                var propertyDto = property.ToModel();

                //Get new api resource property
                var apiResourcePropertiesDto = await apiResourceService.GetApiResourcePropertyAsync(property.Id);

                //Assert
                apiResourcePropertiesDto.Should().BeEquivalentTo(propertyDto, options =>
                                                                 options.Excluding(o => o.ApiResourcePropertyId)
                                                                 .Excluding(o => o.ApiResourceName));
            }
        }