File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
src/libraries/Microsoft.Extensions.Configuration.Json/tests Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -219,5 +219,28 @@ public void ThrowFormatExceptionWhenFileIsEmpty()
219219 var exception = Assert . Throws < FormatException > ( ( ) => LoadProvider ( @"" ) ) ;
220220 Assert . Contains ( "Could not parse the JSON file." , exception . Message ) ;
221221 }
222+
223+ [ Fact ]
224+ public void AddJsonFile_FileProvider_Is_Not_Disposed_When_SourcesGetReloaded ( )
225+ {
226+ string filePath = Path . Combine ( Path . GetTempPath ( ) , $ "{ nameof ( AddJsonFile_FileProvider_Is_Not_Disposed_When_SourcesGetReloaded ) } .json") ;
227+ File . WriteAllText ( filePath , @"{ ""some"": ""value"" }" ) ;
228+
229+ IConfigurationBuilder builder = new ConfigurationManager ( ) ;
230+
231+ builder . AddJsonFile ( filePath , optional : false ) ;
232+
233+ FileConfigurationSource fileConfigurationSource = ( FileConfigurationSource ) builder . Sources . Last ( ) ;
234+ PhysicalFileProvider fileProvider = ( PhysicalFileProvider ) fileConfigurationSource . FileProvider ;
235+
236+ Assert . False ( GetIsDisposed ( fileProvider ) ) ;
237+
238+ builder . Properties . Add ( "simplest" , "repro" ) ;
239+
240+ Assert . False ( GetIsDisposed ( fileProvider ) ) ;
241+
242+ fileProvider . Dispose ( ) ;
243+ Assert . True ( GetIsDisposed ( fileProvider ) ) ;
244+ }
222245 }
223246}
You can’t perform that action at this time.
0 commit comments