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:
@ -3,6 +3,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Configuration.ChangeTracking;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Shouldly;
|
||||
@ -16,6 +17,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
public class DiskFileConfigurationRepositoryTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IWebHostEnvironment> _hostingEnvironment;
|
||||
private readonly Mock<IOcelotConfigurationChangeTokenSource> _changeTokenSource;
|
||||
private IFileConfigurationRepository _repo;
|
||||
private string _environmentSpecificPath;
|
||||
private string _ocelotJsonPath;
|
||||
@ -35,7 +37,9 @@ namespace Ocelot.UnitTests.Configuration
|
||||
_semaphore.Wait();
|
||||
_hostingEnvironment = new Mock<IWebHostEnvironment>();
|
||||
_hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
|
||||
_repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
|
||||
_changeTokenSource = new Mock<IOcelotConfigurationChangeTokenSource>(MockBehavior.Strict);
|
||||
_changeTokenSource.Setup(m => m.Activate());
|
||||
_repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object, _changeTokenSource.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -70,6 +74,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.When(_ => WhenISetTheConfiguration())
|
||||
.Then(_ => ThenTheConfigurationIsStoredAs(config))
|
||||
.And(_ => ThenTheConfigurationJsonIsIndented(config))
|
||||
.And(x => AndTheChangeTokenIsActivated())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -117,7 +122,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
_environmentName = null;
|
||||
_hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
|
||||
_repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
|
||||
_repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object, _changeTokenSource.Object);
|
||||
}
|
||||
|
||||
private void GivenIHaveAConfiguration(FileConfiguration fileConfiguration)
|
||||
@ -210,6 +215,11 @@ namespace Ocelot.UnitTests.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private void AndTheChangeTokenIsActivated()
|
||||
{
|
||||
_changeTokenSource.Verify(m => m.Activate(), Times.Once);
|
||||
}
|
||||
|
||||
private FileConfiguration FakeFileConfigurationForSet()
|
||||
{
|
||||
var reRoutes = new List<FileReRoute>
|
||||
@ -222,11 +232,11 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
Host = "123.12.12.12",
|
||||
Port = 80,
|
||||
}
|
||||
},
|
||||
},
|
||||
DownstreamScheme = "https",
|
||||
DownstreamPathTemplate = "/asdfs/test/{test}"
|
||||
}
|
||||
DownstreamPathTemplate = "/asdfs/test/{test}",
|
||||
},
|
||||
};
|
||||
|
||||
var globalConfiguration = new FileGlobalConfiguration
|
||||
|
Reference in New Issue
Block a user