mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:10:50 +08:00 
			
		
		
		
	Feature/base url in config (#234)
* started moving baseurl to config issue 233 * fixed test
This commit is contained in:
		@@ -15,46 +15,62 @@ namespace Ocelot.UnitTests.Middleware
 | 
			
		||||
{
 | 
			
		||||
    public class BaseUrlFinderTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly BaseUrlFinder _baseUrlFinder;
 | 
			
		||||
        private readonly Mock<IConfiguration> _config;
 | 
			
		||||
 | 
			
		||||
        private BaseUrlFinder _baseUrlFinder;
 | 
			
		||||
        private IConfiguration _config;
 | 
			
		||||
        private List<KeyValuePair<string, string>> _data;
 | 
			
		||||
        private string _result;
 | 
			
		||||
 | 
			
		||||
        public BaseUrlFinderTests()
 | 
			
		||||
        {
 | 
			
		||||
            _config = new Mock<IConfiguration>();
 | 
			
		||||
            _baseUrlFinder = new BaseUrlFinder(_config.Object);
 | 
			
		||||
            _data = new List<KeyValuePair<string,string>>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_default_base_url()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => GivenTheConfigBaseUrlIs(""))
 | 
			
		||||
              .And(x => GivenTheConfigBaseUrlIs(""))
 | 
			
		||||
              .When(x => WhenIFindTheUrl())
 | 
			
		||||
              .Then(x => ThenTheUrlIs("http://localhost:5000"))
 | 
			
		||||
              .BDDfy();
 | 
			
		||||
            this.When(x => WhenIFindTheUrl())
 | 
			
		||||
                .Then(x => ThenTheUrlIs("http://localhost:5000"))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_file_config_base_url()
 | 
			
		||||
        public void should_use_memory_config_base_url()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => GivenTheConfigBaseUrlIs("http://localhost:7000"))
 | 
			
		||||
                .And(x => GivenTheConfigBaseUrlIs("http://baseurlfromconfig.com:5181"))
 | 
			
		||||
            this.Given(x => GivenTheMemoryBaseUrlIs("http://baseurlfromconfig.com:5181"))
 | 
			
		||||
                .When(x => WhenIFindTheUrl())
 | 
			
		||||
                .Then(x => ThenTheUrlIs("http://baseurlfromconfig.com:5181"))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheConfigBaseUrlIs(string configValue)
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_file_config_base_url()
 | 
			
		||||
        {
 | 
			
		||||
            var configSection = new ConfigurationSection(new ConfigurationRoot(new List<IConfigurationProvider>{new MemoryConfigurationProvider(new MemoryConfigurationSource())}), "");
 | 
			
		||||
            configSection.Value = configValue;
 | 
			
		||||
            _config.Setup(x => x.GetSection(It.IsAny<string>())).Returns(configSection);
 | 
			
		||||
            this.Given(x => GivenTheMemoryBaseUrlIs("http://localhost:7000"))
 | 
			
		||||
                .And(x => GivenTheFileBaseUrlIs("http://baseurlfromconfig.com:5181"))
 | 
			
		||||
                .When(x => WhenIFindTheUrl())
 | 
			
		||||
                .Then(x => ThenTheUrlIs("http://baseurlfromconfig.com:5181"))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheMemoryBaseUrlIs(string configValue)
 | 
			
		||||
        {
 | 
			
		||||
            _data.Add(new KeyValuePair<string, string>("BaseUrl", configValue));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheFileBaseUrlIs(string configValue)
 | 
			
		||||
        {
 | 
			
		||||
            _data.Add(new KeyValuePair<string, string>("GlobalConfiguration:BaseUrl", configValue));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenIFindTheUrl()
 | 
			
		||||
        {
 | 
			
		||||
            var source = new MemoryConfigurationSource();
 | 
			
		||||
            source.InitialData = _data;
 | 
			
		||||
            var provider = new MemoryConfigurationProvider(source);
 | 
			
		||||
            _config = new ConfigurationRoot(new List<IConfigurationProvider>() {
 | 
			
		||||
                provider
 | 
			
		||||
            });
 | 
			
		||||
            _baseUrlFinder = new BaseUrlFinder(_config);
 | 
			
		||||
            _result = _baseUrlFinder.Find();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user