Activate ChangeToken when Ocelot's configuration changes #1037

* Add configuration change token (#1036)

* Add IOptionsMonitor<IInternalConfiguration>

* Activate change token from *ConfigurationRepository instead of FileAndInternalConfigurationSetter; add acceptance & integration tests

* Update documentation

* Use IWebHostEnvironment as IHostingEnvironment deprecated

Co-authored-by: Chris Swinchatt <chrisswinchatt@gmail.com>
This commit is contained in:
Tom Pallister
2020-02-04 20:50:40 +00:00
committed by GitHub
parent 473d50ff36
commit 86e8d66daf
17 changed files with 1546 additions and 1111 deletions

View File

@ -5,6 +5,8 @@ using Ocelot.Responses;
using Shouldly;
using System;
using System.Collections.Generic;
using Moq;
using Ocelot.Configuration.ChangeTracking;
using TestStack.BDDfy;
using Xunit;
@ -16,10 +18,13 @@ namespace Ocelot.UnitTests.Configuration
private IInternalConfiguration _config;
private Response _result;
private Response<IInternalConfiguration> _getResult;
private readonly Mock<IOcelotConfigurationChangeTokenSource> _changeTokenSource;
public InMemoryConfigurationRepositoryTests()
{
_repo = new InMemoryInternalConfigurationRepository();
_changeTokenSource = new Mock<IOcelotConfigurationChangeTokenSource>(MockBehavior.Strict);
_changeTokenSource.Setup(m => m.Activate());
_repo = new InMemoryInternalConfigurationRepository(_changeTokenSource.Object);
}
[Fact]
@ -28,6 +33,7 @@ namespace Ocelot.UnitTests.Configuration
this.Given(x => x.GivenTheConfigurationIs(new FakeConfig("initial", "adminath")))
.When(x => x.WhenIAddOrReplaceTheConfig())
.Then(x => x.ThenNoErrorsAreReturned())
.And(x => AndTheChangeTokenIsActivated())
.BDDfy();
}
@ -71,6 +77,11 @@ namespace Ocelot.UnitTests.Configuration
_result.IsError.ShouldBeFalse();
}
private void AndTheChangeTokenIsActivated()
{
_changeTokenSource.Verify(m => m.Activate(), Times.Once);
}
private class FakeConfig : IInternalConfiguration
{
private readonly string _downstreamTemplatePath;
@ -111,4 +122,4 @@ namespace Ocelot.UnitTests.Configuration
public HttpHandlerOptions HttpHandlerOptions { get; }
}
}
}
}