private NewtonsoftJsonConfigurationProvider LoadProvider(string json) { var p = new NewtonsoftJsonConfigurationProvider(new NewtonsoftJsonConfigurationSource { Optional = true }); p.Load(TestStreamHelpers.StringToStream(json)); return(p); }
protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider(TestSection testConfig) { var jsonBuilder = new StringBuilder(); SectionToJson(jsonBuilder, testConfig); var provider = new NewtonsoftJsonConfigurationProvider( new NewtonsoftJsonConfigurationSource { Optional = true }); var json = jsonBuilder.ToString(); return(provider, () => provider.Load(TestStreamHelpers.StringToStream(json))); }
public void ArraysAreConvertedToKeyValuePairs() { var json = @"{ 'ip': [ '1.2.3.4', '7.8.9.10', '11.12.13.14' ] }"; var jsonConfigSource = new NewtonsoftJsonConfigurationProvider(new NewtonsoftJsonConfigurationSource()); 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 NestedArrays() { var json = @"{ 'ip': [ [ '1.2.3.4', '5.6.7.8' ], [ '9.10.11.12', '13.14.15.16' ], ] }"; var jsonConfigSource = new NewtonsoftJsonConfigurationProvider(new NewtonsoftJsonConfigurationSource()); 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 NewtonsoftJsonConfigurationProvider(new NewtonsoftJsonConfigurationSource()); 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")); }