@@ -229,39 +229,55 @@ public void DisableDefaultIHostEnvironmentValues()
229229 Assert . IsAssignableFrom < PhysicalFileProvider > ( env . ContentRootFileProvider ) ;
230230 }
231231
232- [ Fact ]
233- public void ConfigurationSettingCanInfluenceEnvironment ( )
232+ [ Theory ]
233+ [ InlineData ( true ) ]
234+ [ InlineData ( false ) ]
235+ public void ConfigurationSettingCanInfluenceEnvironment ( bool disableDefaults )
234236 {
237+ var tempPath = Path . GetTempPath ( ) ;
238+
235239 using var config = new ConfigurationManager ( ) ;
236240
237241 config . AddInMemoryCollection ( new KeyValuePair < string , string > [ ]
238242 {
239243 new ( HostDefaults . ApplicationKey , "AppA" ) ,
240244 new ( HostDefaults . EnvironmentKey , "EnvA" ) ,
245+ new ( HostDefaults . ContentRootKey , tempPath )
241246 } ) ;
242247
243248 var builder = new HostApplicationBuilder ( new HostApplicationBuilderSettings
244249 {
245- DisableDefaults = true ,
250+ DisableDefaults = disableDefaults ,
246251 Configuration = config ,
247252 } ) ;
248253
249254 Assert . Equal ( "AppA" , builder . Configuration [ HostDefaults . ApplicationKey ] ) ;
250255 Assert . Equal ( "EnvA" , builder . Configuration [ HostDefaults . EnvironmentKey ] ) ;
256+ Assert . Equal ( tempPath , builder . Configuration [ HostDefaults . ContentRootKey ] ) ;
251257
252258 Assert . Equal ( "AppA" , builder . Environment . ApplicationName ) ;
253259 Assert . Equal ( "EnvA" , builder . Environment . EnvironmentName ) ;
260+ Assert . Equal ( tempPath , builder . Environment . ContentRootPath ) ;
261+ var fileProviderFromBuilder = Assert . IsType < PhysicalFileProvider > ( builder . Environment . ContentRootFileProvider ) ;
262+ Assert . Equal ( tempPath , fileProviderFromBuilder . Root ) ;
254263
255264 using IHost host = builder . Build ( ) ;
256265
257266 var hostEnvironmentFromServices = host . Services . GetRequiredService < IHostEnvironment > ( ) ;
258267 Assert . Equal ( "AppA" , hostEnvironmentFromServices . ApplicationName ) ;
259268 Assert . Equal ( "EnvA" , hostEnvironmentFromServices . EnvironmentName ) ;
269+ Assert . Equal ( tempPath , hostEnvironmentFromServices . ContentRootPath ) ;
270+ var fileProviderFromServices = Assert . IsType < PhysicalFileProvider > ( hostEnvironmentFromServices . ContentRootFileProvider ) ;
271+ Assert . Equal ( tempPath , fileProviderFromServices . Root ) ;
260272 }
261273
262- [ Fact ]
263- public void DirectSettingsOverrideConfigurationSetting ( )
274+ [ Theory ]
275+ [ InlineData ( true ) ]
276+ [ InlineData ( false ) ]
277+ public void DirectSettingsOverrideConfigurationSetting ( bool disableDefaults )
264278 {
279+ var tempPath = Path . GetTempPath ( ) ;
280+
265281 using var config = new ConfigurationManager ( ) ;
266282
267283 config . AddInMemoryCollection ( new KeyValuePair < string , string > [ ]
@@ -272,23 +288,31 @@ public void DirectSettingsOverrideConfigurationSetting()
272288
273289 var builder = new HostApplicationBuilder ( new HostApplicationBuilderSettings
274290 {
275- DisableDefaults = true ,
291+ DisableDefaults = disableDefaults ,
276292 Configuration = config ,
277293 ApplicationName = "AppB" ,
278294 EnvironmentName = "EnvB" ,
295+ ContentRootPath = tempPath ,
279296 } ) ;
280297
281298 Assert . Equal ( "AppB" , builder . Configuration [ HostDefaults . ApplicationKey ] ) ;
282299 Assert . Equal ( "EnvB" , builder . Configuration [ HostDefaults . EnvironmentKey ] ) ;
300+ Assert . Equal ( tempPath , builder . Configuration [ HostDefaults . ContentRootKey ] ) ;
283301
284302 Assert . Equal ( "AppB" , builder . Environment . ApplicationName ) ;
285303 Assert . Equal ( "EnvB" , builder . Environment . EnvironmentName ) ;
304+ Assert . Equal ( tempPath , builder . Environment . ContentRootPath ) ;
305+ var fileProviderFromBuilder = Assert . IsType < PhysicalFileProvider > ( builder . Environment . ContentRootFileProvider ) ;
306+ Assert . Equal ( tempPath , fileProviderFromBuilder . Root ) ;
286307
287308 using IHost host = builder . Build ( ) ;
288309
289310 var hostEnvironmentFromServices = host . Services . GetRequiredService < IHostEnvironment > ( ) ;
290311 Assert . Equal ( "AppB" , hostEnvironmentFromServices . ApplicationName ) ;
291312 Assert . Equal ( "EnvB" , hostEnvironmentFromServices . EnvironmentName ) ;
313+ Assert . Equal ( tempPath , hostEnvironmentFromServices . ContentRootPath ) ;
314+ var fileProviderFromServices = Assert . IsType < PhysicalFileProvider > ( hostEnvironmentFromServices . ContentRootFileProvider ) ;
315+ Assert . Equal ( tempPath , fileProviderFromServices . Root ) ;
292316 }
293317
294318 [ Fact ]
0 commit comments