mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 17:08:15 +08:00
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:
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user