public virtual async Task <GetFeatureListResultDto> GetAsync([NotNull] string providerName, string providerKey) { await CheckProviderPolicy(providerName, providerKey); var result = new GetFeatureListResultDto { Groups = new List <FeatureGroupDto>() }; foreach (var group in FeatureDefinitionManager.GetGroups()) { var groupDto = new FeatureGroupDto { Name = group.Name, DisplayName = group.DisplayName.Localize(StringLocalizerFactory), Features = new List <FeatureDto>() }; foreach (var featureDefinition in group.GetFeaturesWithChildren()) { if (providerName == TenantFeatureValueProvider.ProviderName && CurrentTenant.Id == null && providerKey == null && !featureDefinition.IsAvailableToHost) { continue; } var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, providerName, providerKey); groupDto.Features.Add(new FeatureDto { Name = featureDefinition.Name, DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory), ValueType = featureDefinition.ValueType, Description = featureDefinition.Description?.Localize(StringLocalizerFactory), ParentName = featureDefinition.Parent?.Name, Value = feature.Value, Provider = new FeatureProviderDto { Name = feature.Provider?.Name, Key = feature.Provider?.Key } }); } SetFeatureDepth(groupDto.Features, providerName, providerKey); result.Groups.Add(groupDto); } return(result); }
public void Should_Serialize_And_Deserialize() { var featureListDto = new GetFeatureListResultDto { Groups = new List <FeatureGroupDto> { new FeatureGroupDto { Name = "MyGroup", DisplayName = "MyGroup", Features = new List <FeatureDto> { new FeatureDto { ValueType = new FreeTextStringValueType { Validator = new BooleanValueValidator() } }, new FeatureDto { ValueType = new SelectionStringValueType { ItemSource = new StaticSelectionStringValueItemSource( new LocalizableSelectionStringValueItem { Value = "TestValue", DisplayText = new LocalizableStringInfo("TestResourceName", "TestName") }), Validator = new AlwaysValidValueValidator() } }, new FeatureDto { ValueType = new ToggleStringValueType { Validator = new NumericValueValidator { MaxValue = 1000, MinValue = 10 } } }, new FeatureDto { Provider = new FeatureProviderDto { Name = "FeatureName", Key = "FeatureKey" } } } } } }; var serialized = _jsonSerializer.Serialize(featureListDto, indented: true); var featureListDto2 = _jsonSerializer.Deserialize <GetFeatureListResultDto>(serialized); featureListDto2.ShouldNotBeNull(); featureListDto2.Groups[0].Features[0].ValueType.ShouldBeOfType <FreeTextStringValueType>(); featureListDto2.Groups[0].Features[0].ValueType.Validator.ShouldBeOfType <BooleanValueValidator>(); featureListDto2.Groups[0].Features[1].ValueType.ShouldBeOfType <SelectionStringValueType>(); featureListDto2.Groups[0].Features[1].ValueType.Validator.ShouldBeOfType <AlwaysValidValueValidator>(); featureListDto2.Groups[0].Features[1].ValueType.As <SelectionStringValueType>().ItemSource.Items.ShouldBeOfType <LocalizableSelectionStringValueItem[]>(); featureListDto2.Groups[0].Features[1].ValueType.As <SelectionStringValueType>().ItemSource.Items.ShouldContain(x => x.Value == "TestValue" && x.DisplayText.ResourceName == "TestResourceName" && x.DisplayText.Name == "TestName"); featureListDto2.Groups[0].Features[2].ValueType.ShouldBeOfType <ToggleStringValueType>(); featureListDto2.Groups[0].Features[2].ValueType.Validator.ShouldBeOfType <NumericValueValidator>(); featureListDto2.Groups[0].Features[2].ValueType.Validator.As <NumericValueValidator>().MaxValue.ShouldBe(1000); featureListDto2.Groups[0].Features[2].ValueType.Validator.As <NumericValueValidator>().MinValue.ShouldBe(10); featureListDto2.Groups[0].Features[3].Provider.Name.ShouldBe("FeatureName"); featureListDto2.Groups[0].Features[3].Provider.Key.ShouldBe("FeatureKey"); }