public void should_return_deserialized_config_contents() { var model = new TestConfigured(); _cut.CreateConfigFile(model); var configurationResult = _cut.Get(ConfigurationResult <TestConfigured> .Create()); configurationResult.Result.AppKey.Should().Be(model.AppKey); configurationResult.Result.IsEnabled.Should().Be(model.IsEnabled); configurationResult.Result.EnabledOn.Should().Be(model.EnabledOn); }
public void JsonConfiguration_Does_Not_Throw_On_Optional_Configuration() { var configSource = new JsonConfigurationSource("NotExistingConfig.json", optional: true); configSource.Load(); Assert.Throws <InvalidOperationException>(() => configSource.Get("key")); }
public void SupportAndIgnoreComments() { var json = @"/* Comments */ {/* Comments */ ""name"": /* Comments */ ""test"", ""address"": { ""street"": ""Something street"", /* Comments */ ""zipcode"": ""12345"" } }"; var jsonConfigSrc = new JsonConfigurationSource(TestStreamHelpers.ArbitraryFilePath); jsonConfigSrc.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("test", jsonConfigSrc.Get("name")); Assert.Equal("Something street", jsonConfigSrc.Get("address:street")); Assert.Equal("12345", jsonConfigSrc.Get("address:zipcode")); }
public void ArraysAreConvertedToKeyValuePairs() { var json = @"{ 'ip': [ '1.2.3.4', '7.8.9.10', '11.12.13.14' ] }"; var jsonConfigSource = new JsonConfigurationSource(TestStreamHelpers.ArbitraryFilePath); 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 LoadKeyValuePairsFromValidJson() { var json = @" { 'firstname': 'test', 'test.last.name': 'last.name', 'residential.address': { 'street.name': 'Something street', 'zipcode': '12345' } }"; var jsonConfigSrc = new JsonConfigurationSource(TestStreamHelpers.ArbitraryFilePath); jsonConfigSrc.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal("test", jsonConfigSrc.Get("firstname")); Assert.Equal("last.name", jsonConfigSrc.Get("test.last.name")); Assert.Equal("Something street", jsonConfigSrc.Get("residential.address:STREET.name")); Assert.Equal("12345", jsonConfigSrc.Get("residential.address:zipcode")); }
public void LoadMethodCanHandleEmptyValue() { var json = @" { 'name': '' }"; var jsonConfigSrc = new JsonConfigurationSource(TestStreamHelpers.ArbitraryFilePath); jsonConfigSrc.Load(TestStreamHelpers.StringToStream(json)); Assert.Equal(string.Empty, jsonConfigSrc.Get("name")); }
public void ArrayOfObjects() { var json = @"{ 'ip': [ { 'address': '1.2.3.4', 'hidden': false }, { 'address': '5.6.7.8', 'hidden': true } ] }"; var jsonConfigSource = new JsonConfigurationSource(TestStreamHelpers.ArbitraryFilePath); 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")); }
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 JsonConfigurationSource(TestStreamHelpers.ArbitraryFilePath); 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")); }