예제 #1
0
        public void LoadMethodCanHandleEmptyValue()
        {
            var yaml          = @"name:";
            var yamlConfigSrc = new YamlConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);

            yamlConfigSrc.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal(string.Empty, yamlConfigSrc.Get("name"));
        }
예제 #2
0
        private YamlConfigurationProvider LoadProvider(string Yaml)
        {
            var p = new YamlConfigurationProvider(new YamlConfigurationSource {
                Optional = true
            });

            p.Load(TestStreamHelpers.StringToStream(Yaml));
            return(p);
        }
예제 #3
0
        private YamlConfigurationProvider LoadProviders()
        {
            var provider = new YamlConfigurationProvider(new YamlConfigurationSource()
            {
                Optional = false
            });

            provider.Load(GetYamlStream());
            return(provider);
        }
예제 #4
0
        public void NonObjectRootIsInvalid()
        {
            var yaml          = @"test";
            var yamlConfigPrd = new YamlConfigurationProvider("Foo");

            var exception = Assert.Throws <FormatException>(
                () => yamlConfigPrd.Load(TestStreamHelpers.StringToStream(yaml)));

            Assert.NotNull(exception.Message);
        }
예제 #5
0
        public void FilesWithByteOrderMarkerAreParsedCorrectly()
        {
            var yaml = "setting1: '1'\nsetting2: '2'";

            var yamlConfigSource = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigSource.Load(TestStreamHelpers.StringToStream(yaml, withBom: true));

            Assert.Equal("1", yamlConfigSource.Get("setting1"));
            Assert.Equal("2", yamlConfigSource.Get("setting2"));
        }
예제 #6
0
        public void ArraysAreConvertedToKeyValuePairs()
        {
            var yaml = @"
                ip:
                    - 1.2.3.4
                    - 7.8.9.10
                    - 11.12.13.14";

            var yamlConfigurationProvider = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigurationProvider.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("1.2.3.4", yamlConfigurationProvider.Get("ip:0"));
            Assert.Equal("7.8.9.10", yamlConfigurationProvider.Get("ip:1"));
            Assert.Equal("11.12.13.14", yamlConfigurationProvider.Get("ip:2"));
        }
예제 #7
0
        public void SupportAndIgnoreComments()
        {
            var yaml          = @"# Comments
                # Comments
                name: test #foo
                address:
                    street: Something street # Comments
                    zipcode: 12345";
            var yamlConfigPrd = new YamlConfigurationProvider("Foo");

            yamlConfigPrd.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("test", yamlConfigPrd.Get("name"));
            Assert.Equal("Something street", yamlConfigPrd.Get("address:street"));
            Assert.Equal("12345", yamlConfigPrd.Get("address:zipcode"));
        }
        public void SequencesAreConvertedToKeyValuePairs()
        {
            var yaml = @"
                ip:
                - '1.2.3.4'
                - '7.8.9.10'
                - '11.12.13.14'
            ";

            var yamlConfigSource = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigSource.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("1.2.3.4", yamlConfigSource.Get("ip:0"));
            Assert.Equal("7.8.9.10", yamlConfigSource.Get("ip:1"));
            Assert.Equal("11.12.13.14", yamlConfigSource.Get("ip:2"));
        }
예제 #9
0
        public void LoadKeyValuePairsFromValidYaml()
        {
            var yaml          = @"
firstname: test
test.last.name: last.name
residential.address:
    street.name: Something street
    zipcode: 12345";
            var yamlConfigPrd = new YamlConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);

            yamlConfigPrd.Load(TestStreamHelpers.StringToStream(yaml.TrimStart()));

            Assert.Equal("test", yamlConfigPrd.Get("firstname"));
            Assert.Equal("last.name", yamlConfigPrd.Get("test.last.name"));
            Assert.Equal("Something street", yamlConfigPrd.Get("residential.address:STREET.name"));
            Assert.Equal("12345", yamlConfigPrd.Get("residential.address:zipcode"));
        }
예제 #10
0
        public void NestedArrays()
        {
            var yaml = @"
                ip:
                  - - 1.2.3.4
                    - 5.6.7.8
                  - - 9.10.11.12
                    - 13.14.15.16";

            var yamlConfigurationProvider = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigurationProvider.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("1.2.3.4", yamlConfigurationProvider.Get("ip:0:0"));
            Assert.Equal("5.6.7.8", yamlConfigurationProvider.Get("ip:0:1"));
            Assert.Equal("9.10.11.12", yamlConfigurationProvider.Get("ip:1:0"));
            Assert.Equal("13.14.15.16", yamlConfigurationProvider.Get("ip:1:1"));
        }
예제 #11
0
        public void ArrayOfObjects()
        {
            var yaml = @"
                ip:
                    - address: 1.2.3.4
                      hidden: False
                    - address: 5.6.7.8
                      hidden: True";

            var yamlConfigurationProvider = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigurationProvider.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("1.2.3.4", yamlConfigurationProvider.Get("ip:0:address"));
            Assert.Equal("False", yamlConfigurationProvider.Get("ip:0:hidden"));
            Assert.Equal("5.6.7.8", yamlConfigurationProvider.Get("ip:1:address"));
            Assert.Equal("True", yamlConfigurationProvider.Get("ip:1:hidden"));
        }
        public void SequenceOfObjects()
        {
            var yaml = @"
                ip:
                - address: '1.2.3.4'
                  hidden: false
                - address: '5.6.7.8'
                  hidden: true
            ";

            var yamlConfigSource = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigSource.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("1.2.3.4", yamlConfigSource.Get("ip:0:address"));
            Assert.Equal("false", yamlConfigSource.Get("ip:0:hidden"));
            Assert.Equal("5.6.7.8", yamlConfigSource.Get("ip:1:address"));
            Assert.Equal("true", yamlConfigSource.Get("ip:1:hidden"));
        }
        public void NestedSequences()
        {
            var yaml = @"
                'ip': 
                - 
                  - '1.2.3.4'
                  - '5.6.7.8'
                - 
                  - '9.10.11.12'
                  - '13.14.15.16'
                   ";

            var yamlConfigSource = new YamlConfigurationProvider(new YamlConfigurationSource());

            yamlConfigSource.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("1.2.3.4", yamlConfigSource.Get("ip:0:0"));
            Assert.Equal("5.6.7.8", yamlConfigSource.Get("ip:0:1"));
            Assert.Equal("9.10.11.12", yamlConfigSource.Get("ip:1:0"));
            Assert.Equal("13.14.15.16", yamlConfigSource.Get("ip:1:1"));
        }
예제 #14
0
        public void SupportForMultiple()
        {
            var yaml          = @"---
name: test #foo
address:
    home:
        street: Some Home Address
        zipcode: 12345
    work:
        street: Some Work Address
        zipcode: 54321
...";
            var yamlConfigPrd = new YamlConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);

            yamlConfigPrd.Load(TestStreamHelpers.StringToStream(yaml));

            Assert.Equal("Some Home Address", yamlConfigPrd.Get("address:home:street"));
            Assert.Equal("12345", yamlConfigPrd.Get("address:home:zipcode"));
            Assert.Equal("Some Work Address", yamlConfigPrd.Get("address:work:street"));
            Assert.Equal("54321", yamlConfigPrd.Get("address:work:zipcode"));
        }