mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:30:50 +08:00 
			
		
		
		
	Merge branch 'master' into pitming-feature/MethodTransformer
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
using Ocelot.Configuration.File;
 | 
			
		||||
using System;
 | 
			
		||||
using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -54,6 +55,33 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_trigger_change_token_on_change()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningReloadingConfig(true))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAChangeToken())
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig))
 | 
			
		||||
                .And(x => _steps.GivenIWait(MillisecondsToWaitForChangeToken))
 | 
			
		||||
                .Then(x => _steps.TheChangeTokenShouldBeActive(true))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_trigger_change_token_with_no_change()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningReloadingConfig(false))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAChangeToken())
 | 
			
		||||
                .And(x => _steps.GivenIWait(MillisecondsToWaitForChangeToken)) // Wait for prior activation to expire.
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig))
 | 
			
		||||
                .And(x => _steps.GivenIWait(MillisecondsToWaitForChangeToken))
 | 
			
		||||
                .Then(x => _steps.TheChangeTokenShouldBeActive(false))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private const int MillisecondsToWaitForChangeToken = (int) (OcelotConfigurationChangeToken.PollingIntervalSeconds*1000) - 100;
 | 
			
		||||
 | 
			
		||||
        public void Dispose()
 | 
			
		||||
        {
 | 
			
		||||
            _steps.Dispose();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,6 @@
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
{
 | 
			
		||||
    using Caching;
 | 
			
		||||
    using Configuration.Repository;
 | 
			
		||||
@@ -54,6 +56,7 @@
 | 
			
		||||
        private IWebHostBuilder _webHostBuilder;
 | 
			
		||||
        private WebHostBuilder _ocelotBuilder;
 | 
			
		||||
        private IWebHost _ocelotHost;
 | 
			
		||||
        private IOcelotConfigurationChangeTokenSource _changeToken;
 | 
			
		||||
 | 
			
		||||
        public Steps()
 | 
			
		||||
        {
 | 
			
		||||
@@ -216,6 +219,11 @@
 | 
			
		||||
            _ocelotClient = _ocelotServer.CreateClient();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void GivenIHaveAChangeToken()
 | 
			
		||||
        {
 | 
			
		||||
            _changeToken = _ocelotServer.Host.Services.GetRequiredService<IOcelotConfigurationChangeTokenSource>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -1135,6 +1143,11 @@
 | 
			
		||||
            _ocelotClient = _ocelotServer.CreateClient();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TheChangeTokenShouldBeActive(bool itShouldBeActive)
 | 
			
		||||
        {
 | 
			
		||||
            _changeToken.ChangeToken.HasChanged.ShouldBe(itShouldBeActive);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        public void GivenOcelotIsRunningWithLogger()
 | 
			
		||||
        {
 | 
			
		||||
            _webHostBuilder = new WebHostBuilder();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user