File tree Expand file tree Collapse file tree 3 files changed +35
-6
lines changed
src/Microsoft.FeatureManagement
tests/Tests.FeatureManagement Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -201,15 +201,17 @@ private IEnumerable<IConfigurationSection> GetFeatureDefinitionSections()
201201 {
202202 const string FeatureManagementSectionName = "FeatureManagement" ;
203203
204- if ( _configuration . GetChildren ( ) . Any ( s => s . Key . Equals ( FeatureManagementSectionName , StringComparison . OrdinalIgnoreCase ) ) )
204+ //
205+ // Look for feature definitions under the "FeatureManagement" section
206+ IConfigurationSection featureManagementConfigurationSection = _configuration . GetSection ( FeatureManagementSectionName ) ;
207+
208+ if ( featureManagementConfigurationSection . Exists ( ) )
205209 {
206- //
207- // Look for feature definitions under the "FeatureManagement" section
208- return _configuration . GetSection ( FeatureManagementSectionName ) . GetChildren ( ) ;
210+ return featureManagementConfigurationSection . GetChildren ( ) ;
209211 }
210212 else
211213 {
212- return _configuration . GetChildren ( ) ;
214+ return Enumerable . Empty < IConfigurationSection > ( ) ;
213215 }
214216 }
215217 }
Original file line number Diff line number Diff line change 1111using Microsoft . FeatureManagement ;
1212using Microsoft . FeatureManagement . FeatureFilters ;
1313using System ;
14+ using System . Collections ;
1415using System . Collections . Generic ;
16+ using System . IO ;
1517using System . Linq ;
1618using System . Net ;
1719using System . Net . Http ;
20+ using System . Text ;
1821using System . Threading . Tasks ;
1922using Xunit ;
2023
@@ -71,6 +74,30 @@ public async Task ReadsConfiguration()
7174 Assert . True ( called ) ;
7275 }
7376
77+ [ Fact ]
78+ public async Task ReadsOnlyFeatureManagmentSection ( )
79+ {
80+ MemoryStream stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( "{\" AllowedHosts\" : \" *\" }" ) ) ;
81+ IConfiguration config = new ConfigurationBuilder ( ) . AddJsonStream ( stream ) . Build ( ) ;
82+
83+ var services = new ServiceCollection ( ) ;
84+
85+ services
86+ . AddSingleton ( config )
87+ . AddFeatureManagement ( )
88+ . AddFeatureFilter < TestFilter > ( ) ;
89+
90+ ServiceProvider serviceProvider = services . BuildServiceProvider ( ) ;
91+
92+ IFeatureManager featureManager = serviceProvider . GetRequiredService < IFeatureManager > ( ) ;
93+
94+ await foreach ( string featureName in featureManager . GetFeatureNamesAsync ( ) )
95+ {
96+ // Fail, as no features should be found
97+ Assert . True ( false ) ;
98+ }
99+ }
100+
74101 [ Fact ]
75102 public async Task Integrates ( )
76103 {
Original file line number Diff line number Diff line change 1616 <ItemGroup Condition =" '$(TargetFramework)' == 'netcoreapp2.1'" >
1717 <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.9.0" />
1818 <PackageReference Include =" Microsoft.AspNetCore" Version =" 2.1.7" />
19- <PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 2 .1.1 " />
19+ <PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 3 .1.32 " />
2020 <PackageReference Include =" Microsoft.AspNetCore.TestHost" Version =" 2.1.1" />
2121 <PackageReference Include =" Microsoft.AspNetCore.Mvc" Version =" 2.1.3" />
2222 </ItemGroup >
You can’t perform that action at this time.
0 commit comments