예제 #1
0
        public void ThrowExceptionWhenKeyIsDuplicated()
        {
            var ini          = @"
            [Data:DefaultConnection]
            ConnectionString=TestConnectionString
            Provider=SqlClient
            [Data]
            DefaultConnection:ConnectionString=AnotherTestConnectionString
            Provider=MySql
            ";
            var iniConfigSrc = new IniConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);
            var expectedMsg  = Resources.FormatError_KeyIsDuplicated("Data:DefaultConnection:ConnectionString");

            var exception = Assert.Throws <FormatException>(() => iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)));

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #2
0
        public void LoadKeyValuePairsFromValidIniFileWithoutSectionHeader()
        {
            var ini          = @"
            DefaultConnection:ConnectionString=TestConnectionString
            DefaultConnection:Provider=SqlClient
            Data:Inventory:ConnectionString=AnotherTestConnectionString
            Data:Inventory:Provider=MySql
            ";
            var iniConfigSrc = new IniConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);

            iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini));

            Assert.Equal("TestConnectionString", iniConfigSrc.Get("DefaultConnection:ConnectionString"));
            Assert.Equal("SqlClient", iniConfigSrc.Get("DefaultConnection:Provider"));
            Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:ConnectionString"));
            Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider"));
        }
예제 #3
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"));
        }
        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"));
        }
        protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider(
            TestSection testConfig)
        {
            var iniBuilder = new StringBuilder();

            SectionToIni(iniBuilder, "", testConfig);

            var provider = new IniConfigurationProvider(
                new IniConfigurationSource
            {
                Optional = true
            });

            var ini = iniBuilder.ToString();

            return(provider, () => provider.Load(TestStreamHelpers.StringToStream(ini)));
        }
        protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider(TestSection testConfig)
        {
            var jsonBuilder = new StringBuilder();

            SectionToJson(jsonBuilder, testConfig, includeComma: false);

            var provider = new JsonConfigurationProvider(
                new JsonConfigurationSource
            {
                Optional = true
            });

            var json = jsonBuilder.ToString();

            json = JObject.Parse(json).ToString(); // standardize the json (removing trailing commas)
            return(provider, () => provider.Load(TestStreamHelpers.StringToStream(json)));
        }
예제 #7
0
        public void LoadKeyValuePairsFromValidIniFileWithQuotedValues()
        {
            var ini = "[DefaultConnection]\n" +
                      "ConnectionString=\"TestConnectionString\"\n" +
                      "Provider=\"SqlClient\"\n" +
                      "[Data:Inventory]\n" +
                      "ConnectionString=\"AnotherTestConnectionString\"\n" +
                      "Provider=\"MySql\"";
            var iniConfigSrc = new IniConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);

            iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini));

            Assert.Equal("TestConnectionString", iniConfigSrc.Get("DefaultConnection:ConnectionString"));
            Assert.Equal("SqlClient", iniConfigSrc.Get("DefaultConnection:Provider"));
            Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:ConnectionString"));
            Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider"));
        }
예제 #8
0
        public void LoadKeyValuePairsFromValidIniFile()
        {
            var ini          = @"[DefaultConnection]
ConnectionString=TestConnectionString
Provider=SqlClient
[Data:Inventory]
ConnectionString=AnotherTestConnectionString
SubHeader:Provider=MySql";
            var iniConfigSrc = new IniConfigurationProvider(TestStreamHelpers.ArbitraryFilePath);

            iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini));

            Assert.Equal("TestConnectionString", iniConfigSrc.Get("defaultconnection:ConnectionString"));
            Assert.Equal("SqlClient", iniConfigSrc.Get("DEFAULTCONNECTION:PROVIDER"));
            Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:CONNECTIONSTRING"));
            Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:SubHeader:Provider"));
        }
예제 #9
0
        public void ArraysAreConvertedToKeyValuePairs()
        {
            var json = @"{
                ""ip"": [
                    ""1.2.3.4"",
                    ""7.8.9.10"",
                    ""11.12.13.14""
                ]
            }";

            var jsonConfigSource = new JsonConfigurationProvider(new JsonConfigurationSource());

            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"));
        }
예제 #10
0
        public void SupportAndIgnoreComments()
        {
            var json          = @"/* Comments */
                {/* Comments */
                ""name"": /* Comments */ ""test"",
                ""address"": {
                    ""street"": ""Something street"", /* Comments */
                    ""zipcode"": ""12345""
                }
            }";
            var jsonConfigSrc = new JsonConfigurationProvider(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"));
        }
예제 #11
0
        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"));
        }
예제 #12
0
        public void CanLoadValidJsonFromStreamProvider()
        {
            var json   = @"
{
    ""firstname"": ""test"",
    ""test.last.name"": ""last.name"",
        ""residential.address"": {
            ""street.name"": ""Something street"",
            ""zipcode"": ""12345""
        }
}";
            var config = new ConfigurationBuilder().AddNewtonsoftJsonStream(TestStreamHelpers.StringToStream(json)).Build();

            Assert.Equal("test", config["firstname"]);
            Assert.Equal("last.name", config["test.last.name"]);
            Assert.Equal("Something street", config["residential.address:STREET.name"]);
            Assert.Equal("12345", config["residential.address:zipcode"]);
        }
        public void Load_WithConfigValues_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 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"));
        }
예제 #15
0
        public void SupportAndIgnoreComments()
        {
            var yaml          = @"# Comments
                # Comments
                name: test #foo
                address:
                    street: Something street # Comments
                    zipcode: 12345";
            var yamlConfigPrd = new YamlConfigurationProvider(new YamlConfigurationSource
            {
                Path     = "Foo",
                Optional = false
            });

            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"));
        }
예제 #16
0
        public void SupportMixingNameAttributesAndCommonAttributes()
        {
            var xml =
                @"<settings>
                    <Data Name='DefaultConnection'
                          ConnectionString='TestConnectionString'
                          Provider='SqlClient' />
                    <Data Name='Inventory' ConnectionString='AnotherTestConnectionString'>
                          <Provider>MySql</Provider>
                    </Data>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath);

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
            Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
            Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
            Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
        }
예제 #17
0
        public void LoadKeyValuePairsFromValidJson()
        {
            var json          = @"
{
    'firstname': 'test',
    'test.last.name': 'last.name',
        'residential.address': {
            'street.name': 'Something street',
            'zipcode': '12345'
        }
}";
            var jsonConfigSrc = new JsonConfigurationProvider(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 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"));
        }
예제 #19
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"));
        }
예제 #20
0
        public void ThrowExceptionWhenFindNamespace()
        {
            var xml =
                @"<settings xmlns:MyNameSpace='http://microsoft.com/wwa/mynamespace'>
                    <MyNameSpace:Data>
                        <DefaultConnection>
                            <ConnectionString>TestConnectionString</ConnectionString>
                            <Provider>SqlClient</Provider>
                        </DefaultConnection>
                        <Inventory>
                            <ConnectionString>AnotherTestConnectionString</ConnectionString>
                            <Provider>MySql</Provider>
                        </Inventory>
                    </MyNameSpace:Data>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath);
            var expectedMsg  = Resources.FormatError_NamespaceIsNotSupported(Resources.FormatMsg_LineInfo(1, 11));

            var exception = Assert.Throws <FormatException>(() => xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml)));

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #21
0
        public void ThrowExceptionWhenKeyIsDuplicated()
        {
            var xml =
                @"<settings>
                    <Data>
                        <DefaultConnection>
                            <ConnectionString>TestConnectionString</ConnectionString>
                            <Provider>SqlClient</Provider>
                        </DefaultConnection>
                    </Data>
                    <Data Name='DefaultConnection' ConnectionString='NewConnectionString'>
                        <Provider>NewProvider</Provider>
                    </Data>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath);
            var expectedMsg  = Resources.FormatError_KeyIsDuplicated("Data:DefaultConnection:ConnectionString",
                                                                     Resources.FormatMsg_LineInfo(8, 52));

            var exception = Assert.Throws <FormatException>(() => xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml)));

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #22
0
        public void NameAttributeInRootElementContributesToPrefix()
        {
            var xml =
                @"<settings Name='Data'>
                    <DefaultConnection>
                        <ConnectionString>TestConnectionString</ConnectionString>
                        <Provider>SqlClient</Provider>
                    </DefaultConnection>
                    <Inventory>
                        <ConnectionString>AnotherTestConnectionString</ConnectionString>
                        <Provider>MySql</Provider>
                    </Inventory>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath);

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
            Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
            Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
            Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
        }
예제 #23
0
        public void NameAttributeCanBeUsedToSimulateArrays()
        {
            var xml =
                @"<settings>
                  <DefaultConnection Name='0'>
                      <ConnectionString>TestConnectionString1</ConnectionString>
                      <Provider>SqlClient1</Provider>
                  </DefaultConnection>
                  <DefaultConnection Name='1'>
                      <ConnectionString>TestConnectionString2</ConnectionString>
                      <Provider>SqlClient2</Provider>
                  </DefaultConnection>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationProvider(new XmlConfigurationSource());

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString1", xmlConfigSrc.Get("DefaultConnection:0:ConnectionString"));
            Assert.Equal("SqlClient1", xmlConfigSrc.Get("DefaultConnection:0:Provider"));
            Assert.Equal("TestConnectionString2", xmlConfigSrc.Get("DefaultConnection:1:ConnectionString"));
            Assert.Equal("SqlClient2", xmlConfigSrc.Get("DefaultConnection:1:Provider"));
        }
예제 #24
0
        public void RepeatedElementDetectionIsCaseInsensitive()
        {
            var xml =
                @"<settings>
                  <DefaultConnection>
                      <ConnectionString>TestConnectionString1</ConnectionString>
                      <Provider>SqlClient1</Provider>
                  </DefaultConnection>
                  <defaultconnection>
                      <ConnectionString>TestConnectionString2</ConnectionString>
                      <Provider>SqlClient2</Provider>
                  </defaultconnection>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationProvider(new XmlConfigurationSource());

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString1", xmlConfigSrc.Get("DefaultConnection:0:ConnectionString"));
            Assert.Equal("SqlClient1", xmlConfigSrc.Get("DefaultConnection:0:Provider"));
            Assert.Equal("TestConnectionString2", xmlConfigSrc.Get("DefaultConnection:1:ConnectionString"));
            Assert.Equal("SqlClient2", xmlConfigSrc.Get("DefaultConnection:1:Provider"));
        }
예제 #25
0
        public void SupportAndIgnoreComments()
        {
            var ini          = @"
            ; Comments
            [DefaultConnection]
            # Comments
            ConnectionString=TestConnectionString
            / Comments
            Provider=SqlClient
            [Data:Inventory]
            ConnectionString=AnotherTestConnectionString
            Provider=MySql
            ";
            var iniConfigSrc = new IniConfigurationProvider(new IniConfigurationSource());

            iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini));

            Assert.Equal("TestConnectionString", iniConfigSrc.Get("DefaultConnection:ConnectionString"));
            Assert.Equal("SqlClient", iniConfigSrc.Get("DefaultConnection:Provider"));
            Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:ConnectionString"));
            Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider"));
        }
예제 #26
0
        public void ThrowExceptionWhenKeyIsDuplicatedWithDifferentCasing()
        {
            var xml =
                @"<settings>
                    <Data>
                        <DefaultConnection>
                            <ConnectionString>TestConnectionString</ConnectionString>
                            <Provider>SqlClient</Provider>
                        </DefaultConnection>
                    </Data>
                    <data name='defaultconnection' connectionstring='NewConnectionString'>
                        <provider>NewProvider</provider>
                    </data>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationProvider(new XmlConfigurationSource());
            var expectedMsg  = SR.Format(SR.Error_KeyIsDuplicated, "data:defaultconnection:connectionstring",
                                         SR.Format(SR.Msg_LineInfo, 8, 52));

            var exception = Assert.Throws <FormatException>(() => xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml)));

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #27
0
        public void NameAttributeContributesToPrefix()
        {
            var xml =
                @"<settings>
                    <Data Name='DefaultConnection'>
                        <ConnectionString>TestConnectionString</ConnectionString>
                        <Provider>SqlClient</Provider>
                    </Data>
                    <Data Name='Inventory'>
                        <ConnectionString>AnotherTestConnectionString</ConnectionString>
                        <Provider>MySql</Provider>
                    </Data>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationProvider(new XmlConfigurationSource());

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
            Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
            Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
            Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
        }
예제 #28
0
        public void LoadValidXmlFromStreamProvider()
        {
            var xml    = @"
                <settings>
                    <Data.Setting>
                        <DefaultConnection>
                            <Connection.String>Test.Connection.String</Connection.String>
                            <Provider>SqlClient</Provider>
                        </DefaultConnection>
                        <Inventory>
                            <ConnectionString>AnotherTestConnectionString</ConnectionString>
                            <Provider>MySql</Provider>
                        </Inventory>
                    </Data.Setting>
                </settings>";
            var config = new ConfigurationBuilder().AddXmlStream(TestStreamHelpers.StringToStream(xml)).Build();

            Assert.Equal("Test.Connection.String", config["DATA.SETTING:DEFAULTCONNECTION:CONNECTION.STRING"]);
            Assert.Equal("SqlClient", config["DATA.SETTING:DefaultConnection:Provider"]);
            Assert.Equal("AnotherTestConnectionString", config["data.setting:inventory:connectionstring"]);
            Assert.Equal("MySql", config["Data.setting:Inventory:Provider"]);
        }
예제 #29
0
        public void RepeatedElementsWithDifferentNamesContributeToPrefix()
        {
            var xml =
                @"<settings>
                  <DefaultConnection Name='Data1'>
                      <ConnectionString>TestConnectionString1</ConnectionString>
                      <Provider>SqlClient1</Provider>
                  </DefaultConnection>
                  <DefaultConnection Name='Data2'>
                      <ConnectionString>TestConnectionString2</ConnectionString>
                      <Provider>SqlClient2</Provider>
                  </DefaultConnection>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationProvider(new XmlConfigurationSource());

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString1", xmlConfigSrc.Get("DefaultConnection:Data1:ConnectionString"));
            Assert.Equal("SqlClient1", xmlConfigSrc.Get("DefaultConnection:Data1:Provider"));
            Assert.Equal("TestConnectionString2", xmlConfigSrc.Get("DefaultConnection:Data2:ConnectionString"));
            Assert.Equal("SqlClient2", xmlConfigSrc.Get("DefaultConnection:Data2:Provider"));
        }
예제 #30
0
        public void NestedRepeatedElementsContributeToPrefix()
        {
            var xml =
                @"<settings>
                  <DefaultConnection>
                      <ConnectionString>TestConnectionString1</ConnectionString>
                      <ConnectionString>TestConnectionString2</ConnectionString>
                  </DefaultConnection>
                  <DefaultConnection>
                      <ConnectionString>TestConnectionString3</ConnectionString>
                      <ConnectionString>TestConnectionString4</ConnectionString>
                  </DefaultConnection>
                </settings>";
            var xmlConfigSrc = new XmlConfigurationProvider(new XmlConfigurationSource());

            xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));

            Assert.Equal("TestConnectionString1", xmlConfigSrc.Get("DefaultConnection:0:ConnectionString:0"));
            Assert.Equal("TestConnectionString2", xmlConfigSrc.Get("DefaultConnection:0:ConnectionString:1"));
            Assert.Equal("TestConnectionString3", xmlConfigSrc.Get("DefaultConnection:1:ConnectionString:0"));
            Assert.Equal("TestConnectionString4", xmlConfigSrc.Get("DefaultConnection:1:ConnectionString:1"));
        }