示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
        public async void RemoteLoadAsync_ConfigServerReturnsLessThanBadRequest()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Reset();
            TestConfigServerStartup.ReturnStatus = new int[] { 204 };
            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
            ConfigEnvironment result = await provider.RemoteLoadAsync(settings.GetRawUris(), null);

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.Null(result);
        }
示例#6
0
        public async void RemoteLoadAsync_ConfigServerReturnsGood()
        {
            // 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
            ConfigEnvironment env = await provider.RemoteLoadAsync(settings.GetUris(), null);

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.NotNull(env);
            Assert.Equal("testname", env.Name);
            Assert.NotNull(env.Profiles);
            Assert.Single(env.Profiles);
            Assert.Equal("testlabel", env.Label);
            Assert.Equal("testversion", env.Version);
            Assert.NotNull(env.PropertySources);
            Assert.Single(env.PropertySources);
            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 async Task RemoteLoadAsync_ConfigServerReturnsGood()
        {
            // Arrange
            var environment = @"
                {
                    ""name"": ""testname"",
                    ""profiles"": [""Production""],
                    ""label"": ""testlabel"",
                    ""version"": ""testversion"",
                    ""propertySources"": [ 
                        { 
                            ""name"": ""source"",
                            ""source"": {
                                ""key1"": ""value1"",
                                ""key2"": 10
                            }
                        }
                    ]
                }";
            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://localhost:8888",
                Name = "myName"
            };

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

            // Act and Assert
            var env = await provider.RemoteLoadAsync(settings.GetUris(), null);

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.NotNull(env);
            Assert.Equal("testname", env.Name);
            Assert.NotNull(env.Profiles);
            Assert.Single(env.Profiles);
            Assert.Equal("testlabel", env.Label);
            Assert.Equal("testversion", env.Version);
            Assert.NotNull(env.PropertySources);
            Assert.Single(env.PropertySources);
            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"].ToString());
            Assert.Equal(10L, long.Parse(env.PropertySources[0].Source["key2"].ToString()));
        }
示例#8
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);
        }
示例#9
0
        public void DoLoad_MultipleLabels_ChecksAllLabels()
        {
            // 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;
            TestConfigServerStartup.ReturnStatus = new int[] { 404, 200 };
            TestConfigServerStartup.Label        = "testlabel";
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

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

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

            // Act and Assert
            provider.DoLoad();

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal(2, TestConfigServerStartup.RequestCount);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment + "/testlabel", TestConfigServerStartup.LastRequest.Path.Value);
        }
        public void Load_ChangesDataDictionary()
        {
            // Arrange
            var environment = @"
                {
                    ""name"": ""testname"",
                    ""profiles"": [""Production""],
                    ""label"": ""testlabel"",
                    ""version"": ""testversion"",
                    ""propertySources"": [ 
                        { 
                            ""name"": ""source"",
                            ""source"": {
                                ""key1"": ""value1"",
                                ""key2"": 10
                            }
                        }
                    ]
                }";
            var envir       = HostingHelpers.GetHostingEnvironment();

            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.LoadInternal();
            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 DoLoad_MultipleLabels_ChecksAllLabels()
        {
            // Arrange
            var environment = @"
                {
                    ""name"": ""testname"",
                    ""profiles"": [""Production""],
                    ""label"": ""testlabel"",
                    ""version"": ""testversion"",
                    ""propertySources"": [ 
                        { 
                            ""name"": ""source"",
                            ""source"": {
                                ""key1"": ""value1"",
                                ""key2"": 10
                            }
                        }
                    ]
                }";
            var envir       = HostingHelpers.GetHostingEnvironment();

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

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

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

            // Act and Assert
            provider.DoLoad();

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal(2, TestConfigServerStartup.RequestCount);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment + "/testlabel", TestConfigServerStartup.LastRequest.Path.Value);
        }
        public void Load_ConfigServerReturnsNotFoundStatus_FailFastEnabled()
        {
            // Arrange
            var envir = HostingHelpers.GetHostingEnvironment();

            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",
                FailFast = true
            };

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

            // Act and Assert
            var ex = Assert.Throws <ConfigServerException>(() => provider.LoadInternal());
        }
        public async Task RemoteLoadAsync_ConfigServerReturnsGreaterThanEqualBadRequest()
        {
            // Arrange
            TestConfigServerStartup.Reset();
            TestConfigServerStartup.ReturnStatus = new int[] { 500 };
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment("testing");

            using var server = new TestServer(builder);
            var settings = new ConfigServerClientSettings
            {
                Uri  = "http://localhost:8888",
                Name = "myName"
            };

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

            // Act and Assert
            var ex = await Assert.ThrowsAsync <HttpRequestException>(() => provider.RemoteLoadAsync(settings.GetUris(), null));

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
        }
        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 _));
        }