Remove Ocelot specific Middleware to make Ocelot more compatible with kestrel middleware and get ready for YARP

This commit is contained in:
Tom Pallister
2020-05-23 15:48:51 +01:00
committed by GitHub
parent 99a15d8668
commit fe3e8bd23a
214 changed files with 9574 additions and 9919 deletions

View File

@ -1,7 +1,4 @@
using System;
using System.Threading.Tasks;
namespace Ocelot.UnitTests.Middleware
namespace Ocelot.UnitTests.Middleware
{
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@ -11,19 +8,22 @@ namespace Ocelot.UnitTests.Middleware
using Ocelot.DependencyInjection;
using Ocelot.Logging;
using Ocelot.Middleware;
using Ocelot.Middleware.Pipeline;
using Shouldly;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Ocelot.Errors.Middleware;
using TestStack.BDDfy;
using Xunit;
using System;
using System.Threading.Tasks;
public class OcelotPiplineBuilderTests
{
private readonly IServiceCollection _services;
private readonly IConfiguration _configRoot;
private DownstreamContext _downstreamContext;
private int _counter;
private HttpContext _httpContext;
public OcelotPiplineBuilderTests()
{
@ -32,6 +32,7 @@ namespace Ocelot.UnitTests.Middleware
_services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
_services.AddSingleton<IConfiguration>(_configRoot);
_services.AddOcelot();
_httpContext = new DefaultHttpContext();
}
@ -64,61 +65,58 @@ namespace Ocelot.UnitTests.Middleware
private void WhenIUseAGeneric()
{
var provider = _services.BuildServiceProvider();
IOcelotPipelineBuilder builder = new OcelotPipelineBuilder(provider);
builder = builder.UseMiddleware<Ocelot.Errors.Middleware.ExceptionHandlerMiddleware>();
IApplicationBuilder builder = new ApplicationBuilder(provider);
builder = builder.UseMiddleware<ExceptionHandlerMiddleware>();
var del = builder.Build();
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
del.Invoke(_downstreamContext);
del.Invoke(_httpContext);
}
private void ThenTheGenericIsInThePipeline()
{
_downstreamContext.HttpContext.Response.StatusCode.ShouldBe(500);
_httpContext.Response.StatusCode.ShouldBe(500);
}
private void WhenIUseAFunc()
{
_counter = 0;
var provider = _services.BuildServiceProvider();
IOcelotPipelineBuilder builder = new OcelotPipelineBuilder(provider);
IApplicationBuilder builder = new ApplicationBuilder(provider);
builder = builder.Use(async (ctx, next) =>
{
_counter++;
await next.Invoke();
});
var del = builder.Build();
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
del.Invoke(_downstreamContext);
del.Invoke(_httpContext);
}
private void ThenTheFuncIsInThePipeline()
{
_counter.ShouldBe(1);
_downstreamContext.HttpContext.Response.StatusCode.ShouldBe(404);
_httpContext.Response.StatusCode.ShouldBe(404);
}
[Fact]
public void Middleware_Multi_Parameters_Invoke()
{
var provider = _services.BuildServiceProvider();
IOcelotPipelineBuilder builder = new OcelotPipelineBuilder(provider);
IApplicationBuilder builder = new ApplicationBuilder(provider);
builder = builder.UseMiddleware<MultiParametersInvokeMiddleware>();
var del = builder.Build();
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
del.Invoke(_downstreamContext);
del.Invoke(_httpContext);
}
private class MultiParametersInvokeMiddleware : OcelotMiddleware
{
private readonly OcelotRequestDelegate _next;
private readonly RequestDelegate _next;
public MultiParametersInvokeMiddleware(OcelotRequestDelegate next)
public MultiParametersInvokeMiddleware(RequestDelegate next)
: base(new FakeLogger())
{
_next = next;
}
public Task Invoke(DownstreamContext context, IServiceProvider serviceProvider)
public Task Invoke(HttpContext context, IServiceProvider serviceProvider)
{
return Task.CompletedTask;
}