mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-18 21:28:16 +08:00
Feature/refactoring internal config creation stack (#600)
* tidy up some code so I can understand it * broke al the things that make config out into their own classes etc..sigh * fix the things i broked * #597 test for issue, works on this branch :E * #597 removed comments * added tests for new load balancer creator..basic * added tests for lb creator and aggregates creator * added tests for config creator * boiler plate for tests * added dynamics tests * wip * finished refactoring for now
This commit is contained in:
124
test/Ocelot.UnitTests/Configuration/ConfigurationCreatorTests.cs
Normal file
124
test/Ocelot.UnitTests/Configuration/ConfigurationCreatorTests.cs
Normal file
@ -0,0 +1,124 @@
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
public class ConfigurationCreatorTests
|
||||
{
|
||||
private ConfigurationCreator _creator;
|
||||
private InternalConfiguration _result;
|
||||
private readonly Mock<IServiceProviderConfigurationCreator> _spcCreator;
|
||||
private readonly Mock<IQoSOptionsCreator> _qosCreator;
|
||||
private readonly Mock<IHttpHandlerOptionsCreator> _hhoCreator;
|
||||
private readonly Mock<ILoadBalancerOptionsCreator> _lboCreator;
|
||||
private FileConfiguration _fileConfig;
|
||||
private List<ReRoute> _reRoutes;
|
||||
private ServiceProviderConfiguration _spc;
|
||||
private LoadBalancerOptions _lbo;
|
||||
private QoSOptions _qoso;
|
||||
private HttpHandlerOptions _hho;
|
||||
private AdministrationPath _adminPath;
|
||||
private readonly ServiceCollection _serviceCollection;
|
||||
|
||||
public ConfigurationCreatorTests()
|
||||
{
|
||||
_lboCreator = new Mock<ILoadBalancerOptionsCreator>();
|
||||
_hhoCreator = new Mock<IHttpHandlerOptionsCreator>();
|
||||
_qosCreator = new Mock<IQoSOptionsCreator>();
|
||||
_spcCreator = new Mock<IServiceProviderConfigurationCreator>();
|
||||
_serviceCollection = new ServiceCollection();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_build_configuration_with_no_admin_path()
|
||||
{
|
||||
this.Given(_ => GivenTheDependenciesAreSetUp())
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheDepdenciesAreCalledCorrectly())
|
||||
.And(_ => ThenThePropertiesAreSetCorrectly())
|
||||
.And(_ => ThenTheAdminPathIsNull())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_build_configuration_with_admin_path()
|
||||
{
|
||||
this.Given(_ => GivenTheDependenciesAreSetUp())
|
||||
.And(_ => GivenTheAdminPath())
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheDepdenciesAreCalledCorrectly())
|
||||
.And(_ => ThenThePropertiesAreSetCorrectly())
|
||||
.And(_ => ThenTheAdminPathIsSet())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenTheAdminPathIsNull()
|
||||
{
|
||||
_result.AdministrationPath.ShouldBeNull();
|
||||
}
|
||||
|
||||
private void ThenThePropertiesAreSetCorrectly()
|
||||
{
|
||||
_result.ShouldNotBeNull();
|
||||
_result.ServiceProviderConfiguration.ShouldBe(_spc);
|
||||
_result.LoadBalancerOptions.ShouldBe(_lbo);
|
||||
_result.QoSOptions.ShouldBe(_qoso);
|
||||
_result.HttpHandlerOptions.ShouldBe(_hho);
|
||||
_result.ReRoutes.ShouldBe(_reRoutes);
|
||||
_result.RequestId.ShouldBe(_fileConfig.GlobalConfiguration.RequestIdKey);
|
||||
_result.DownstreamScheme.ShouldBe(_fileConfig.GlobalConfiguration.DownstreamScheme);
|
||||
}
|
||||
|
||||
private void ThenTheAdminPathIsSet()
|
||||
{
|
||||
_result.AdministrationPath.ShouldBe("wooty");
|
||||
}
|
||||
|
||||
private void ThenTheDepdenciesAreCalledCorrectly()
|
||||
{
|
||||
_spcCreator.Verify(x => x.Create(_fileConfig.GlobalConfiguration), Times.Once);
|
||||
_lboCreator.Verify(x => x.Create(_fileConfig.GlobalConfiguration.LoadBalancerOptions), Times.Once);
|
||||
_qosCreator.Verify(x => x.Create(_fileConfig.GlobalConfiguration.QoSOptions), Times.Once);
|
||||
_hhoCreator.Verify(x => x.Create(_fileConfig.GlobalConfiguration.HttpHandlerOptions), Times.Once);
|
||||
}
|
||||
|
||||
private void GivenTheAdminPath()
|
||||
{
|
||||
_adminPath = new AdministrationPath("wooty");
|
||||
_serviceCollection.AddSingleton<IAdministrationPath>(_adminPath);
|
||||
}
|
||||
|
||||
private void GivenTheDependenciesAreSetUp()
|
||||
{
|
||||
_fileConfig = new FileConfiguration
|
||||
{
|
||||
GlobalConfiguration = new FileGlobalConfiguration()
|
||||
};
|
||||
_reRoutes = new List<ReRoute>();
|
||||
_spc = new ServiceProviderConfiguration("", "", 1, "", "", 1);
|
||||
_lbo = new LoadBalancerOptionsBuilder().Build();
|
||||
_qoso = new QoSOptions(1, 1, 1, "");
|
||||
_hho = new HttpHandlerOptionsBuilder().Build();
|
||||
|
||||
_spcCreator.Setup(x => x.Create(It.IsAny<FileGlobalConfiguration>())).Returns(_spc);
|
||||
_lboCreator.Setup(x => x.Create(It.IsAny<FileLoadBalancerOptions>())).Returns(_lbo);
|
||||
_qosCreator.Setup(x => x.Create(It.IsAny<FileQoSOptions>())).Returns(_qoso);
|
||||
_hhoCreator.Setup(x => x.Create(It.IsAny<FileHttpHandlerOptions>())).Returns(_hho);
|
||||
}
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
var serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
_creator = new ConfigurationCreator(_spcCreator.Object, _qosCreator.Object, _hhoCreator.Object, serviceProvider, _lboCreator.Object);
|
||||
_result = _creator.Create(_fileConfig, _reRoutes);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user