private JsonConfigurationProvider LoadProvider(string json) { var p = new JsonTemplateConfigurationProvider(new JsonTemplateConfigurationSource { Optional = true }); p.Load(TestStreamHelpers.StringToStream(json)); return(p); }
public void Load_WithConfigValues_Applies_Values() { var json = @"{ 'setting1': '$var1$', 'setting2': '$var2$', 'setting3': 'value3', }"; var provider = new JsonTemplateConfigurationProvider(new MockJsonTemplateConfigurationSource()); provider.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("var1_value", provider.Get("setting1")); Assert.Equal("var2_value", provider.Get("setting2")); Assert.Equal("value3", provider.Get("setting3")); }
public void ArraysAreConvertedToKeyValuePairs() { var json = @"{ 'ip': [ '1.2.3.4', '7.8.9.10', '11.12.13.14' ] }"; var jsonConfigSource = new JsonTemplateConfigurationProvider(new JsonTemplateConfigurationSource()); jsonConfigSource.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("1.2.3.4", jsonConfigSource.Get("ip:0")); Assert.Equal("7.8.9.10", jsonConfigSource.Get("ip:1")); Assert.Equal("11.12.13.14", jsonConfigSource.Get("ip:2")); }
public void Load_with_config_values_and_nested_variables_applies_values() { var json = @"{ 'setting1': '$var1$', 'setting2': { 'subsetting1': 'subsetting1_val', 'subsetting2': '$var2$', 'subsetting3': 'f', } }"; var provider = new JsonTemplateConfigurationProvider(new MockJsonTemplateConfigurationSource()); provider.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("var1_value", provider.Get("setting1")); Assert.Equal("var2_value", provider.Get("setting2:subsetting2")); Assert.Equal("subsetting1_val", provider.Get("setting2:subsetting1")); }
public void NestedArrays() { var json = @"{ 'ip': [ [ '1.2.3.4', '5.6.7.8' ], [ '9.10.11.12', '13.14.15.16' ], ] }"; var jsonConfigSource = new JsonTemplateConfigurationProvider(new JsonTemplateConfigurationSource()); jsonConfigSource.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("1.2.3.4", jsonConfigSource.Get("ip:0:0")); Assert.Equal("5.6.7.8", jsonConfigSource.Get("ip:0:1")); Assert.Equal("9.10.11.12", jsonConfigSource.Get("ip:1:0")); Assert.Equal("13.14.15.16", jsonConfigSource.Get("ip:1:1")); }
public void ArrayOfObjects() { var json = @"{ 'ip': [ { 'address': '1.2.3.4', 'hidden': false }, { 'address': '5.6.7.8', 'hidden': true } ] }"; var jsonConfigSource = new JsonTemplateConfigurationProvider(new JsonTemplateConfigurationSource()); jsonConfigSource.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("1.2.3.4", jsonConfigSource.Get("ip:0:address")); Assert.Equal("False", jsonConfigSource.Get("ip:0:hidden")); Assert.Equal("5.6.7.8", jsonConfigSource.Get("ip:1:address")); Assert.Equal("True", jsonConfigSource.Get("ip:1:hidden")); }