Skip to content

Commit 44a2f26

Browse files
adamsitnikgithub-actions
authored andcommitted
Add test to ensure the bug does not come back
1 parent b6d2144 commit 44a2f26

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libraries/Microsoft.Extensions.Configuration.Json/tests/JsonConfigurationTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)