2727using System . Xml . Linq ;
2828
2929using Patterns . Configuration ;
30+ using Patterns . Text . RegularExpressions ;
3031
3132namespace Patterns . Testing . Configuration
3233{
@@ -37,6 +38,7 @@ namespace Patterns.Testing.Configuration
3738 public class TestConfigurationSource : IConfigurationSource
3839 {
3940 private readonly XContainer _configXml ;
41+ private readonly CompiledRegex _sectionNamePattern = "[^/]+$" ;
4042
4143 /// <summary>
4244 /// Initializes a new instance of the <see cref="TestConfigurationSource" /> class.
@@ -149,11 +151,11 @@ public IConfiguration OpenExeConfiguration(ConfigurationUserLevel userLevel)
149151 throw new NotSupportedException ( ) ;
150152 }
151153
152- private static ConfigurationSection DeserializeSection ( XContainer xml , string name )
154+ private ConfigurationSection DeserializeSection ( XContainer xml , string name )
153155 {
154156 XElement sectionDefinition = xml . Element ( "configSections" )
155- . Elements ( "section" )
156- . FirstOrDefault ( section => section . Attribute ( "name" ) . Value == name ) ;
157+ . Descendants ( "section" )
158+ . FirstOrDefault ( section => section . Attribute ( "name" ) . Value == _sectionNamePattern . Match ( name ) . Value ) ;
157159
158160 if ( sectionDefinition == null ) return null ;
159161
@@ -182,7 +184,7 @@ private static ConfigurationSection DeserializeSection(XContainer xml, string na
182184 var config = new TSection ( ) ;
183185 const BindingFlags flags = BindingFlags . Instance | BindingFlags . NonPublic ;
184186 MethodInfo deserializer = typeof ( TSection ) . GetMethod ( "DeserializeSection" , flags ) ;
185- XElement sectionXml = xml . Element ( name ) ;
187+ var sectionXml = name . Split ( '/' ) . Aggregate ( xml , ( current , part ) => current . Element ( part ) ) ;
186188 if ( sectionXml == null ) return null ;
187189
188190 try
0 commit comments