Example #1
0
    public async Task RaiseChangeEventAfterProviderSetToNull()
    {
        var testFileProvider = new TestFileProvider(
            new TestFile("Secret1", "SecretValue1"),
            new TestFile("Secret2", "SecretValue2"));
        var configurationSource = new KeyPerFileConfigurationSource
        {
            FileProvider = testFileProvider,
            Optional     = true,
        };
        var keyPerFileProvider = new KeyPerFileConfigurationProvider(configurationSource);
        var config             = new ConfigurationRoot(new[] { keyPerFileProvider });

        var changeToken          = config.GetReloadToken();
        var changeTaskCompletion = new TaskCompletionSource <object>();

        changeToken.RegisterChangeCallback(state =>
                                           ((TaskCompletionSource <object>)state).TrySetResult(null), changeTaskCompletion);

        configurationSource.FileProvider = null;
        config.Reload();

        await changeTaskCompletion.Task;

        Assert.Empty(config.AsEnumerable());
    }
        public string GetConfigurations()
        {
            ConfigurationRoot root = configuration as ConfigurationRoot;
            var providers          = root.AsEnumerable()
                                     .Where(pair => pair.Value != null);

            var config = JsonConvert.SerializeObject(providers);

            return(config);
        }