public void Load_ChangesDataDictionary()
        {
            // Arrange
            var environment = @"
{
    'name': 'testname',
    'profiles': ['Production'],
    'label': 'testlabel',
    'version': 'testversion',
    'propertySources': [ 
        { 
            'name': 'source',
            'source': {
                'key1': 'value1',
                'key2': 10
            }
        }
    ]
}";
            var startup = new TestConfigServerStartup(environment, 200);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
            settings.Uri = "http://localhost:8888";
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());

            // Act and Assert
            provider.Load();
            Assert.NotNull(startup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);

            string value;
            Assert.True(provider.TryGet("key1", out value));
            Assert.Equal("value1", value);
            Assert.True(provider.TryGet("key2", out value));
            Assert.Equal("10", value);
        }
        public void Load_ConfigServerReturnsBadStatus_FailFastEnabled()
        {
            // Arrange
            var startup = new TestConfigServerStartup("", 500);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
            settings.Uri = "http://localhost:8888";
            settings.Name = "myName";
            settings.FailFast = true;
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());

            // Act and Assert
            var ex = Assert.Throws<ConfigServerException>(() => provider.Load());

        }
        public async void RemoteLoadAsync_ConfigServerReturnsGood()
        {
            // Arrange
            var environment = @"
{
    'name': 'testname',
    'profiles': ['Production'],
    'label': 'testlabel',
    'version': 'testversion',
    'propertySources': [ 
        { 
            'name': 'source',
            'source': {
                'key1': 'value1',
                'key2': 10
            }
        }
    ]
}";
            var startup = new TestConfigServerStartup(environment, 200);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
            settings.Uri ="http://localhost:8888";
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
            string path = provider.GetConfigServerUri(null);

            // Act and Assert
            Environment env = await provider.RemoteLoadAsync(path);
            Assert.NotNull(startup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
            Assert.NotNull(env);
            Assert.Equal("testname", env.Name);
            Assert.NotNull(env.Profiles);
            Assert.Equal(1, env.Profiles.Count);
            Assert.Equal("testlabel", env.Label);
            Assert.Equal("testversion", env.Version);
            Assert.NotNull(env.PropertySources);
            Assert.Equal(1, env.PropertySources.Count);
            Assert.Equal("source", env.PropertySources[0].Name);
            Assert.NotNull(env.PropertySources[0].Source);
            Assert.Equal(2, env.PropertySources[0].Source.Count);
            Assert.Equal("value1", env.PropertySources[0].Source["key1"]);
            Assert.Equal((long)10, env.PropertySources[0].Source["key2"]);
        }
        public void Load_ConfigServerReturnsNotFoundStatus()
        {
            // Arrange
            var startup = new TestConfigServerStartup("", 404);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
            settings.Uri = "http://localhost:8888";
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());

            // Act and Assert
            provider.Load();
            Assert.NotNull(startup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
            Assert.Equal(9, provider.Properties.Count);
        }
        public async void RemoteLoadAsync_ConfigServerReturnsLessThanBadRequest()
        {
            // Arrange
            var startup = new TestConfigServerStartup("", 204);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
            settings.Uri = "http://localhost:8888";
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient());
            string path = provider.GetConfigServerUri(null);

            // Act and Assert
            Environment result = await provider.RemoteLoadAsync(path);

            Assert.NotNull(startup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
            Assert.Null(result);

        }