public void ProviderSeesConfigUpdates() { var appSettings1 = @"{ ""redis"": { ""client"": { ""host"": ""testHost"" } } }"; var appSettings2 = @"{ ""redis"": { ""client"": { ""host"": ""updatedTestHost"" } } }"; using var sandbox = new Sandbox(); var path = sandbox.CreateFile("appsettings.json", appSettings1); var directory = Path.GetDirectoryName(path); var fileName = Path.GetFileName(path); var baseProviders = new ConfigurationBuilder().SetBasePath(directory).AddJsonFile(fileName, false, true).Build().Providers; var provider = new ConnectionStringConfigurationProvider(baseProviders); var token = provider.GetReloadToken(); Assert.True(provider.TryGet("connectionstrings:redis", out var connectionString)); Assert.Equal("testHost:6379,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", connectionString); File.WriteAllText(path, appSettings2); Thread.Sleep(2000); Assert.True(token.HasChanged); Assert.True(provider.TryGet("connectionstrings:redis", out connectionString)); Assert.Equal("updatedTestHost:6379,allowAdmin=false,abortConnect=true,resolveDns=false,ssl=false", connectionString); }
public void TryGetReturnsFalseWhenNotFound() { var provider = new ConnectionStringConfigurationProvider(new ConfigurationBuilder().Build().Providers); Assert.False(provider.TryGet("connectionstrings:myRedisService", out _)); }