public void ArrayMerge() { var hocon1 = @"{ 'ip': [ '1.2.3.4', '7.8.9.10', '11.12.13.14' ] }"; var hocon2 = @"{ 'ip': { '3': '15.16.17.18' } }"; var hoconConfigSource1 = new HoconConfigurationSource { FileProvider = TestStreamHelpers.StringToFileProvider(hocon1) }; var hoconConfigSource2 = new HoconConfigurationSource { FileProvider = TestStreamHelpers.StringToFileProvider(hocon2) }; var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.Add(hoconConfigSource1); configurationBuilder.Add(hoconConfigSource2); var config = configurationBuilder.Build(); Assert.Equal(4, config.GetSection("ip").GetChildren().Count()); Assert.Equal("1.2.3.4", config["ip:0"]); Assert.Equal("7.8.9.10", config["ip:1"]); Assert.Equal("11.12.13.14", config["ip:2"]); Assert.Equal("15.16.17.18", config["ip:3"]); }
public void NestedArrays() { var hocon = @"{ 'ip': [ [ '1.2.3.4', '5.6.7.8' ], [ '9.10.11.12', '13.14.15.16' ], ] }"; var hoconConfigSource = new HoconConfigurationProvider(new HoconConfigurationSource()); hoconConfigSource.Load(TestStreamHelpers.StringToStream(hocon)); Assert.Equal("1.2.3.4", hoconConfigSource.Get("ip:0:0")); Assert.Equal("5.6.7.8", hoconConfigSource.Get("ip:0:1")); Assert.Equal("9.10.11.12", hoconConfigSource.Get("ip:1:0")); Assert.Equal("13.14.15.16", hoconConfigSource.Get("ip:1:1")); }
public void ArrayOfObjects() { var hocon = @"{ 'ip': [ { 'address': '1.2.3.4', 'hidden': false }, { 'address': '5.6.7.8', 'hidden': true } ] }"; var hoconConfigSource = new HoconConfigurationProvider(new HoconConfigurationSource()); hoconConfigSource.Load(TestStreamHelpers.StringToStream(hocon)); Assert.Equal("1.2.3.4", hoconConfigSource.Get("ip:0:address")); Assert.Equal("false", hoconConfigSource.Get("ip:0:hidden")); Assert.Equal("5.6.7.8", hoconConfigSource.Get("ip:1:address")); Assert.Equal("true", hoconConfigSource.Get("ip:1:hidden")); }