mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 04:18:16 +08:00
hacked together load balancing reroutes in fileconfig (#211)
* hacked together load balancing reroutes in fileconfig * some renaming and refactoring * more renames * hacked away the old config json * test for issue 213 * renamed key * dont share ports * oops * updated docs * mvoed docs around * port being used
This commit is contained in:
@ -1,91 +1,91 @@
|
||||
using Xunit;
|
||||
using Shouldly;
|
||||
using Ocelot.Headers.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Headers;
|
||||
|
||||
namespace Ocelot.UnitTests.Headers
|
||||
{
|
||||
public class HttpContextRequestHeaderReplacerTests
|
||||
{
|
||||
private HttpContext _context;
|
||||
private List<HeaderFindAndReplace> _fAndRs;
|
||||
private HttpContextRequestHeaderReplacer _replacer;
|
||||
private Response _result;
|
||||
|
||||
public HttpContextRequestHeaderReplacerTests()
|
||||
{
|
||||
_replacer = new HttpContextRequestHeaderReplacer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_replace_headers()
|
||||
{
|
||||
var context = new DefaultHttpContext();
|
||||
context.Request.Headers.Add("test", "test");
|
||||
|
||||
var fAndRs = new List<HeaderFindAndReplace>();
|
||||
fAndRs.Add(new HeaderFindAndReplace("test", "test", "chiken", 0));
|
||||
|
||||
this.Given(x => GivenTheFollowingHttpRequest(context))
|
||||
.And(x => GivenTheFollowingHeaderReplacements(fAndRs))
|
||||
.When(x => WhenICallTheReplacer())
|
||||
.Then(x => ThenTheHeadersAreReplaced())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_replace_headers()
|
||||
{
|
||||
var context = new DefaultHttpContext();
|
||||
context.Request.Headers.Add("test", "test");
|
||||
|
||||
var fAndRs = new List<HeaderFindAndReplace>();
|
||||
|
||||
this.Given(x => GivenTheFollowingHttpRequest(context))
|
||||
.And(x => GivenTheFollowingHeaderReplacements(fAndRs))
|
||||
.When(x => WhenICallTheReplacer())
|
||||
.Then(x => ThenTheHeadersAreNotReplaced())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenTheHeadersAreNotReplaced()
|
||||
{
|
||||
_result.ShouldBeOfType<OkResponse>();
|
||||
foreach (var f in _fAndRs)
|
||||
{
|
||||
_context.Request.Headers.TryGetValue(f.Key, out var values);
|
||||
values[f.Index].ShouldBe("test");
|
||||
}
|
||||
}
|
||||
|
||||
private void GivenTheFollowingHttpRequest(HttpContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
private void GivenTheFollowingHeaderReplacements(List<HeaderFindAndReplace> fAndRs)
|
||||
{
|
||||
_fAndRs = fAndRs;
|
||||
}
|
||||
|
||||
private void WhenICallTheReplacer()
|
||||
{
|
||||
_result = _replacer.Replace(_context, _fAndRs);
|
||||
}
|
||||
|
||||
private void ThenTheHeadersAreReplaced()
|
||||
{
|
||||
_result.ShouldBeOfType<OkResponse>();
|
||||
foreach (var f in _fAndRs)
|
||||
{
|
||||
_context.Request.Headers.TryGetValue(f.Key, out var values);
|
||||
values[f.Index].ShouldBe(f.Replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
using Xunit;
|
||||
using Shouldly;
|
||||
using Ocelot.Headers.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Headers;
|
||||
|
||||
namespace Ocelot.UnitTests.Headers
|
||||
{
|
||||
public class HttpContextRequestHeaderReplacerTests
|
||||
{
|
||||
private HttpContext _context;
|
||||
private List<HeaderFindAndReplace> _fAndRs;
|
||||
private HttpContextRequestHeaderReplacer _replacer;
|
||||
private Response _result;
|
||||
|
||||
public HttpContextRequestHeaderReplacerTests()
|
||||
{
|
||||
_replacer = new HttpContextRequestHeaderReplacer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_replace_headers()
|
||||
{
|
||||
var context = new DefaultHttpContext();
|
||||
context.Request.Headers.Add("test", "test");
|
||||
|
||||
var fAndRs = new List<HeaderFindAndReplace>();
|
||||
fAndRs.Add(new HeaderFindAndReplace("test", "test", "chiken", 0));
|
||||
|
||||
this.Given(x => GivenTheFollowingHttpRequest(context))
|
||||
.And(x => GivenTheFollowingHeaderReplacements(fAndRs))
|
||||
.When(x => WhenICallTheReplacer())
|
||||
.Then(x => ThenTheHeadersAreReplaced())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_replace_headers()
|
||||
{
|
||||
var context = new DefaultHttpContext();
|
||||
context.Request.Headers.Add("test", "test");
|
||||
|
||||
var fAndRs = new List<HeaderFindAndReplace>();
|
||||
|
||||
this.Given(x => GivenTheFollowingHttpRequest(context))
|
||||
.And(x => GivenTheFollowingHeaderReplacements(fAndRs))
|
||||
.When(x => WhenICallTheReplacer())
|
||||
.Then(x => ThenTheHeadersAreNotReplaced())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenTheHeadersAreNotReplaced()
|
||||
{
|
||||
_result.ShouldBeOfType<OkResponse>();
|
||||
foreach (var f in _fAndRs)
|
||||
{
|
||||
_context.Request.Headers.TryGetValue(f.Key, out var values);
|
||||
values[f.Index].ShouldBe("test");
|
||||
}
|
||||
}
|
||||
|
||||
private void GivenTheFollowingHttpRequest(HttpContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
private void GivenTheFollowingHeaderReplacements(List<HeaderFindAndReplace> fAndRs)
|
||||
{
|
||||
_fAndRs = fAndRs;
|
||||
}
|
||||
|
||||
private void WhenICallTheReplacer()
|
||||
{
|
||||
_result = _replacer.Replace(_context, _fAndRs);
|
||||
}
|
||||
|
||||
private void ThenTheHeadersAreReplaced()
|
||||
{
|
||||
_result.ShouldBeOfType<OkResponse>();
|
||||
foreach (var f in _fAndRs)
|
||||
{
|
||||
_context.Request.Headers.TryGetValue(f.Key, out var values);
|
||||
values[f.Index].ShouldBe(f.Replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user