mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 14:48:14 +08:00
Remove Ocelot specific Middleware to make Ocelot more compatible with kestrel middleware and get ready for YARP
This commit is contained in:
@ -21,19 +21,19 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
private readonly CookieStickySessions _stickySessions;
|
||||
private readonly Mock<ILoadBalancer> _loadBalancer;
|
||||
private readonly int _defaultExpiryInMs;
|
||||
private DownstreamContext _downstreamContext;
|
||||
private Response<ServiceHostAndPort> _result;
|
||||
private Response<ServiceHostAndPort> _firstHostAndPort;
|
||||
private Response<ServiceHostAndPort> _secondHostAndPort;
|
||||
private readonly FakeBus<StickySession> _bus;
|
||||
private HttpContext _httpContext;
|
||||
|
||||
public CookieStickySessionsTests()
|
||||
{
|
||||
_httpContext = new DefaultHttpContext();
|
||||
_bus = new FakeBus<StickySession>();
|
||||
_loadBalancer = new Mock<ILoadBalancer>();
|
||||
_defaultExpiryInMs = 0;
|
||||
_stickySessions = new CookieStickySessions(_loadBalancer.Object, "sessionid", _defaultExpiryInMs, _bus);
|
||||
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -116,7 +116,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
private void GivenTheLoadBalancerReturnsError()
|
||||
{
|
||||
_loadBalancer
|
||||
.Setup(x => x.Lease(It.IsAny<DownstreamContext>()))
|
||||
.Setup(x => x.Lease(It.IsAny<HttpContext>()))
|
||||
.ReturnsAsync(new ErrorResponse<ServiceHostAndPort>(new AnyError()));
|
||||
}
|
||||
|
||||
@ -138,14 +138,14 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
var cookiesTwo = new FakeCookies();
|
||||
cookiesTwo.AddCookie("sessionid", "123");
|
||||
contextTwo.Request.Cookies = cookiesTwo;
|
||||
_firstHostAndPort = await _stickySessions.Lease(new DownstreamContext(contextOne));
|
||||
_secondHostAndPort = await _stickySessions.Lease(new DownstreamContext(contextTwo));
|
||||
_firstHostAndPort = await _stickySessions.Lease(contextOne);
|
||||
_secondHostAndPort = await _stickySessions.Lease(contextTwo);
|
||||
}
|
||||
|
||||
private void GivenTheLoadBalancerReturnsSequence()
|
||||
{
|
||||
_loadBalancer
|
||||
.SetupSequence(x => x.Lease(It.IsAny<DownstreamContext>()))
|
||||
.SetupSequence(x => x.Lease(It.IsAny<HttpContext>()))
|
||||
.ReturnsAsync(new OkResponse<ServiceHostAndPort>(new ServiceHostAndPort("one", 80)))
|
||||
.ReturnsAsync(new OkResponse<ServiceHostAndPort>(new ServiceHostAndPort("two", 80)));
|
||||
}
|
||||
@ -158,8 +158,8 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
|
||||
private async Task WhenILeaseTwiceInARow()
|
||||
{
|
||||
_firstHostAndPort = await _stickySessions.Lease(_downstreamContext);
|
||||
_secondHostAndPort = await _stickySessions.Lease(_downstreamContext);
|
||||
_firstHostAndPort = await _stickySessions.Lease(_httpContext);
|
||||
_secondHostAndPort = await _stickySessions.Lease(_httpContext);
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamRequestHasSessionId(string value)
|
||||
@ -168,19 +168,19 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
var cookies = new FakeCookies();
|
||||
cookies.AddCookie("sessionid", value);
|
||||
context.Request.Cookies = cookies;
|
||||
_downstreamContext = new DownstreamContext(context);
|
||||
_httpContext = context;
|
||||
}
|
||||
|
||||
private void GivenTheLoadBalancerReturns()
|
||||
{
|
||||
_loadBalancer
|
||||
.Setup(x => x.Lease(It.IsAny<DownstreamContext>()))
|
||||
.Setup(x => x.Lease(It.IsAny<HttpContext>()))
|
||||
.ReturnsAsync(new OkResponse<ServiceHostAndPort>(new ServiceHostAndPort("", 80)));
|
||||
}
|
||||
|
||||
private async Task WhenILease()
|
||||
{
|
||||
_result = await _stickySessions.Lease(_downstreamContext);
|
||||
_result = await _stickySessions.Lease(_httpContext);
|
||||
}
|
||||
|
||||
private void ThenTheHostAndPortIsNotNull()
|
||||
|
Reference in New Issue
Block a user