Example #1
0
        public virtual async Task <bool> CanInsertApiResourcePropertyAsync(ApiResourceProperty apiResourceProperty)
        {
            var existsWithSameName = await DbContext.ApiResourceProperties.Where(x => x.Key == apiResourceProperty.Key &&
                                                                                 x.ApiResource.Id == apiResourceProperty.ApiResourceId).SingleOrDefaultAsync();

            return(existsWithSameName == null);
        }
Example #2
0
        public virtual async Task <int> DeleteApiResourcePropertyAsync(ApiResourceProperty apiResourceProperty)
        {
            var propertyToDelete = await DbContext.ApiResourceProperties.Where(x => x.Id == apiResourceProperty.Id).SingleOrDefaultAsync();

            DbContext.ApiResourceProperties.Remove(propertyToDelete);
            return(await AutoSaveChangesAsync());
        }
Example #3
0
        public async Task <int> AddApiResourcePropertyAsync(int apiResourceId, ApiResourceProperty apiResourceProperty)
        {
            var apiResource = await _dbContext.ApiResources.Where(x => x.Id == apiResourceId).SingleOrDefaultAsync();

            apiResourceProperty.ApiResource = apiResource;
            await _dbContext.ApiResourceProperties.AddAsync(apiResourceProperty);

            return(await AutoSaveChangesAsync());
        }
 public static ApiResourcePropertyModel FromEntity(ApiResourceProperty entity)
 {
     return(new ApiResourcePropertyModel
     {
         Id = entity.Id,
         Key = entity.Key,
         Value = entity.Value,
         ApiResource = new ApiResourceModel
         {
             Id = entity.ApiResource.Id,
             Name = entity.ApiResource.Name,
         },
     });
 }
Example #5
0
 public static ApiResourcePropertyModel ToModel(this ApiResourceProperty property)
 {
     return(Mapper.Map <ApiResourcePropertyModel>(property));
 }
 public static ApiResourcePropertiesDto ToModel(this ApiResourceProperty apiResourceProperty)
 {
     return(Mapper.Map <ApiResourcePropertiesDto>(apiResourceProperty));
 }
 public async Task <bool> DeleteApiResourceProperty(ApiResourceProperty apiResourceProperty)
 {
     return(await _repository.DeleteAsync(apiResourceProperty));
 }
 public async Task <int> InsertApiResourceProperty(ApiResourceProperty apiResourceProperty)
 {
     return(await _repository.InsertAsync(apiResourceProperty));
 }
        public async Task OnPostAsync()
        {
            // Arrange
            const string property1OriginalValue = "Original Value";
            const string property1EditedValue   = "Edited Value";
            const string newPropertyValue       = "New Value";
            var          databaseName           = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}";
            var          options = new DbContextOptionsBuilder <IdentityServerDbContext>()
                                   .UseInMemoryDatabase(databaseName)
                                   .Options;
            PropertiesModel properties;
            IActionResult   post;
            var             property1 = new ApiResourceProperty
            {
                Id    = Random.Next(),
                Value = property1OriginalValue
            };
            var property2 = new ApiResourceProperty {
                Id = Random.Next()
            };
            var apiResourceId = Random.Next();
            var apiResource   = new ApiResource
            {
                Id         = apiResourceId,
                Properties = new List <ApiResourceProperty>
                {
                    property1,
                    property2
                }
            };

            using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object))
            {
                context.Add(apiResource);
                await context.SaveChangesAsync().ConfigureAwait(false);
            }

            // Act
            using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object))
            {
                properties = new PropertiesModel(context)
                {
                    ApiResource = new ApiResource
                    {
                        Id         = apiResourceId,
                        Properties = new List <ApiResourceProperty>
                        {
                            new ApiResourceProperty
                            {
                                Id    = property1.Id,
                                Value = property1EditedValue
                            },
                            new ApiResourceProperty {
                                Value = newPropertyValue
                            }
                        }
                    }
                };
                post = await properties.OnPostAsync().ConfigureAwait(false);
            }

            // Assert
            using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object))
            {
                apiResource = await context.ApiResources
                              .Include(x => x.Properties)
                              .SingleOrDefaultAsync(x => x.Id.Equals(apiResourceId))
                              .ConfigureAwait(false);

                property1 = apiResource.Properties.SingleOrDefault(x => x.Id.Equals(property1.Id));
                property2 = apiResource.Properties.SingleOrDefault(x => x.Id.Equals(property2.Id));
                var newProperty = apiResource.Properties.SingleOrDefault(x => x.Value.Equals(newPropertyValue));

                Assert.NotNull(property1);
                Assert.Equal(property1EditedValue, property1.Value);
                Assert.Null(property2);
                Assert.NotNull(newProperty);
            }

            var result = Assert.IsType <RedirectToPageResult>(post);

            Assert.Equal("../Details/Properties", result.PageName);
            Assert.Collection(result.RouteValues, routeValue =>
            {
                var(key, value) = routeValue;
                Assert.Equal(nameof(ApiResource.Id), key);
                Assert.Equal(properties.ApiResource.Id, value);
            });
        }