mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-05-02 00:02:51 +08:00

* hacking around to work out why logging and request id isnt working * pass request id into logger so it can be structured, removed a bunch of debug logging we dont need because diagnostic trace gets it * changed config dependency * always have tracing available * made it so we dont need to pass config into services.AddOcelot anymore with .net core 2.0 * add test * lots of changes relating to logging and request ids, also updated documentation * fixed failing test i missed
92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using Ocelot.Configuration.Creator;
|
|
using Ocelot.Configuration.File;
|
|
using Shouldly;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
namespace Ocelot.UnitTests.Configuration
|
|
{
|
|
public class RequestIdKeyCreatorTests
|
|
{
|
|
private FileReRoute _fileReRoute;
|
|
private FileGlobalConfiguration _fileGlobalConfig;
|
|
private string _result;
|
|
private RequestIdKeyCreator _creator;
|
|
|
|
public RequestIdKeyCreatorTests()
|
|
{
|
|
_creator = new RequestIdKeyCreator();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_use_global_configuration()
|
|
{
|
|
var reRoute = new FileReRoute();
|
|
var globalConfig = new FileGlobalConfiguration
|
|
{
|
|
RequestIdKey = "cheese"
|
|
};
|
|
|
|
this.Given(x => x.GivenTheFollowingReRoute(reRoute))
|
|
.And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
|
|
.When(x => x.WhenICreate())
|
|
.Then(x => x.ThenTheFollowingIsReturned("cheese"))
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_use_re_route_specific()
|
|
{
|
|
var reRoute = new FileReRoute
|
|
{
|
|
RequestIdKey = "cheese"
|
|
};
|
|
var globalConfig = new FileGlobalConfiguration();
|
|
|
|
this.Given(x => x.GivenTheFollowingReRoute(reRoute))
|
|
.And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
|
|
.When(x => x.WhenICreate())
|
|
.Then(x => x.ThenTheFollowingIsReturned("cheese"))
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_use_re_route_over_global_specific()
|
|
{
|
|
var reRoute = new FileReRoute
|
|
{
|
|
RequestIdKey = "cheese"
|
|
};
|
|
var globalConfig = new FileGlobalConfiguration
|
|
{
|
|
RequestIdKey = "test"
|
|
};
|
|
|
|
this.Given(x => x.GivenTheFollowingReRoute(reRoute))
|
|
.And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
|
|
.When(x => x.WhenICreate())
|
|
.Then(x => x.ThenTheFollowingIsReturned("cheese"))
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenTheFollowingReRoute(FileReRoute fileReRoute)
|
|
{
|
|
_fileReRoute = fileReRoute;
|
|
}
|
|
|
|
private void GivenTheFollowingGlobalConfig(FileGlobalConfiguration globalConfig)
|
|
{
|
|
_fileGlobalConfig = globalConfig;
|
|
}
|
|
|
|
private void WhenICreate()
|
|
{
|
|
_result = _creator.Create(_fileReRoute, _fileGlobalConfig);
|
|
}
|
|
|
|
private void ThenTheFollowingIsReturned(string expected)
|
|
{
|
|
_result.ShouldBe(expected);
|
|
}
|
|
}
|
|
} |