Preserve the value of Name Attribute in XmlConfigurationProvider
This commit is contained in:
Родитель
09bc782255
Коммит
7bc4aece14
|
@ -187,11 +187,6 @@ namespace Microsoft.Extensions.Configuration.Xml
|
||||||
private static void AddAttributePair(XmlReader reader, Stack<string> prefixStack,
|
private static void AddAttributePair(XmlReader reader, Stack<string> prefixStack,
|
||||||
IDictionary<string, string> data, XmlWriter writer)
|
IDictionary<string, string> data, XmlWriter writer)
|
||||||
{
|
{
|
||||||
if (string.Equals(reader.LocalName, NameAttributeKey, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
prefixStack.Push(reader.LocalName);
|
prefixStack.Push(reader.LocalName);
|
||||||
var key = ConfigurationPath.Combine(prefixStack.Reverse());
|
var key = ConfigurationPath.Combine(prefixStack.Reverse());
|
||||||
if (data.ContainsKey(key))
|
if (data.ContainsKey(key))
|
||||||
|
|
|
@ -123,8 +123,10 @@ namespace Microsoft.Extensions.Configuration.Xml.Test
|
||||||
|
|
||||||
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
|
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
|
||||||
|
|
||||||
|
Assert.Equal("DefaultConnection", xmlConfigSrc.Get("Data:DefaultConnection:Name"));
|
||||||
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
|
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
|
||||||
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
|
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
|
||||||
|
Assert.Equal("Inventory", xmlConfigSrc.Get("Data:Inventory:Name"));
|
||||||
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
|
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
|
||||||
Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
|
Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
|
||||||
}
|
}
|
||||||
|
@ -147,6 +149,7 @@ namespace Microsoft.Extensions.Configuration.Xml.Test
|
||||||
|
|
||||||
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
|
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
|
||||||
|
|
||||||
|
Assert.Equal("Data", xmlConfigSrc.Get("Data:Name"));
|
||||||
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
|
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
|
||||||
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
|
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
|
||||||
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
|
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
|
||||||
|
@ -169,8 +172,10 @@ namespace Microsoft.Extensions.Configuration.Xml.Test
|
||||||
|
|
||||||
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
|
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
|
||||||
|
|
||||||
|
Assert.Equal("DefaultConnection", xmlConfigSrc.Get("Data:DefaultConnection:Name"));
|
||||||
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
|
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
|
||||||
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
|
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
|
||||||
|
Assert.Equal("Inventory", xmlConfigSrc.Get("Data:Inventory:Name"));
|
||||||
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
|
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
|
||||||
Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
|
Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче