Пример #1
0
        public void Load_ConfigServerReturnsBadStatus_FailFastEnabled_RetryEnabled()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.ReturnStatus = new int[] { 500, 500, 500, 500, 500, 500 };
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings
            {
                Uri          = "http://localhost:8888",
                Name         = "myName",
                FailFast     = true,
                RetryEnabled = true
            };

            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());

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

            Assert.Equal(6, TestConfigServerStartup.RequestCount);
        }
Пример #2
0
        public void Load_ConfigServerReturnsNotFoundStatus()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.ReturnStatus = new int[] { 404 };
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings
            {
                Uri  = "http://localhost:8888",
                Name = "myName"
            };

            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());

            // Act and Assert
            provider.Load();
            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.Equal(25, provider.Properties.Count);
        }
Пример #3
0
        public void Load_MultipleConfigServers_ReturnsNotFoundStatus__DoesNotContinueChecking_FailFastEnabled()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.ReturnStatus = new int[] { 404, 200 };
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings
            {
                Uri      = "http://localhost:8888, http://localhost:8888 ",
                Name     = "myName",
                FailFast = true
            };

            server.BaseAddress = new Uri("http://localhost:8888");
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());

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

            Assert.Equal(1, TestConfigServerStartup.RequestCount);
        }
Пример #4
0
        public void Load_MultipleConfigServers_ReturnsGreaterThanEqualBadRequest_StopsChecking()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.ReturnStatus = new int[] { 500, 200 };
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings
            {
                Uri  = "http://localhost:8888, http://localhost:8888",
                Name = "myName"
            };

            server.BaseAddress = new Uri("http://localhost:8888");
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());

            // Act and Assert
            provider.Load();
            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.Equal(1, TestConfigServerStartup.RequestCount);
        }
Пример #5
0
        public void Load_ChangesDataDictionary()
        {
            // Arrange
            var environment           = @"
{
    'name': 'testname',
    'profiles': ['Production'],
    'label': 'testlabel',
    'version': 'testversion',
    'propertySources': [ 
        { 
            'name': 'source',
            'source': {
                'key1': 'value1',
                'key2': 10
            }
        }
    ]
}";
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.Response = environment;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings
            {
                Uri  = "http://localhost:8888",
                Name = "myName"
            };

            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());

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

            Assert.True(provider.TryGet("key1", out string value));
            Assert.Equal("value1", value);
            Assert.True(provider.TryGet("key2", out value));
            Assert.Equal("10", value);
        }
        public void Load_ConfigServerReturnsBadStatus_FailFastEnabled()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Response     = "";
            TestConfigServerStartup.ReturnStatus = 500;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            settings.Uri       = "http://localhost:8888";
            settings.Name      = "myName";
            settings.FailFast  = true;
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient(), envir);

            // Act and Assert
            var ex = Assert.Throws <ConfigServerException>(() => provider.Load());
        }
        public void ReLoad_DataDictionary_With_New_Configurations()
        {
            // Arrange
            var environment = @"
                    {
                        ""name"": ""testname"",
                        ""profiles"": [""Production""],
                        ""label"": ""testlabel"",
                        ""version"": ""testversion"",
                        ""propertySources"": [ 
                            { 
                                ""name"": ""source"",
                                ""source"": {
                                            ""featureToggles.ShowModule[0]"": ""FT1"",
                                            ""featureToggles.ShowModule[1]"": ""FT2"",
                                            ""featureToggles.ShowModule[2]"": ""FT3"",
                                            ""enableSettings"":""true""
                                    }
                            }
                        ]
                    }";

            var envir = HostingHelpers.GetHostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.Response = environment;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            var settings = new ConfigServerClientSettings
            {
                Uri  = "http://*****:*****@"
                {
                    ""name"": ""testname"",
                    ""profiles"": [""Production""],
                    ""label"": ""testlabel"",
                    ""version"": ""testversion"",
                    ""propertySources"": [ 
                        { 
                            ""name"": ""source"",
                            ""source"": {
                                ""featureToggles.ShowModule[0]"": ""none""
                            }
                        }
                    ]
                }";
            provider.Load();
            Assert.True(provider.TryGet("featureToggles:ShowModule:0", out var val));
            Assert.Equal("none", val);
            Assert.False(provider.TryGet("featureToggles:ShowModule:1", out _));
            Assert.False(provider.TryGet("featureToggles:ShowModule:2", out _));
            Assert.False(provider.TryGet("enableSettings", out _));
        }
        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);
            ConfigServerClientSettings settings = new ConfigServerClientSettings();
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(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_ConfigServerReturnsNotFoundStatus()
        {
            // Arrange
            var startup = new TestConfigServerStartup("", 404);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettings settings = new ConfigServerClientSettings();
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());

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