public async Task RaiseChangeEventWhenDirectoryClearsReloadOnChangeIsTrue() { var testFileProvider = new TestFileProvider( new TestFile("Secret1", "SecretValue1"), new TestFile("Secret2", "SecretValue2")); var config = new ConfigurationBuilder() .AddKeyPerFile(o => { o.FileProvider = testFileProvider; o.ReloadOnChange = true; }).Build(); var changeToken = config.GetReloadToken(); var changeTaskCompletion = new TaskCompletionSource <object>(); changeToken.RegisterChangeCallback(state => ((TaskCompletionSource <object>)state).TrySetResult(null), changeTaskCompletion); testFileProvider.ChangeFiles(); await changeTaskCompletion.Task; Assert.Empty(config.AsEnumerable()); }
public void NoFilesReloadWhenAddedFiles() { var testFileProvider = new TestFileProvider(); var config = new ConfigurationBuilder() .AddKeyPerFile(o => { o.FileProvider = testFileProvider; o.ReloadOnChange = true; o.Optional = true; }).Build(); Assert.Empty(config.AsEnumerable()); testFileProvider.ChangeFiles( new TestFile("Secret1", "SecretValue1"), new TestFile("Secret2", "SecretValue2")); Assert.Equal("SecretValue1", config["Secret1"]); Assert.Equal("SecretValue2", config["Secret2"]); }
public void SameConfigWhenReloadOnChangeIsFalse() { var testFileProvider = new TestFileProvider( new TestFile("Secret1", "SecretValue1"), new TestFile("Secret2", "SecretValue2")); var config = new ConfigurationBuilder() .AddKeyPerFile(o => { o.FileProvider = testFileProvider; o.ReloadOnChange = false; }).Build(); Assert.Equal("SecretValue1", config["Secret1"]); Assert.Equal("SecretValue2", config["Secret2"]); testFileProvider.ChangeFiles( new TestFile("Secret1", "NewSecretValue1"), new TestFile("Secret3", "NewSecretValue3")); Assert.Equal("SecretValue1", config["Secret1"]); Assert.Equal("SecretValue2", config["Secret2"]); }
public async Task RaiseChangeEventAfterStartingWithEmptyDirectoryReloadOnChangeIsTrue() { var testFileProvider = new TestFileProvider(); var config = new ConfigurationBuilder() .AddKeyPerFile(o => { o.FileProvider = testFileProvider; o.ReloadOnChange = true; o.Optional = true; }).Build(); var changeToken = config.GetReloadToken(); var changeTaskCompletion = new TaskCompletionSource <object>(); changeToken.RegisterChangeCallback(state => ((TaskCompletionSource <object>)state).TrySetResult(null), changeTaskCompletion); testFileProvider.ChangeFiles(new TestFile("Secret1", "SecretValue1")); await changeTaskCompletion.Task; Assert.Equal("SecretValue1", config["Secret1"]); }