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

@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Logging;
using Ocelot.Middleware;
using System;
using TestStack.BDDfy;
using Xunit;
@ -16,12 +15,13 @@ namespace Ocelot.UnitTests.Logging
private readonly Mock<IOcelotLogger> _logger;
private IServiceCollection _serviceCollection;
private IServiceProvider _serviceProvider;
private DownstreamContext _downstreamContext;
private string _name;
private Exception _exception;
private HttpContext _httpContext;
public OcelotDiagnosticListenerTests()
{
_httpContext = new DefaultHttpContext();
_factory = new Mock<IOcelotLoggerFactory>();
_logger = new Mock<IOcelotLogger>();
_serviceCollection = new ServiceCollection();
@ -30,44 +30,12 @@ namespace Ocelot.UnitTests.Logging
_listener = new OcelotDiagnosticListener(_factory.Object, _serviceProvider);
}
[Fact]
public void should_trace_ocelot_middleware_started()
{
this.Given(_ => GivenAMiddlewareName())
.And(_ => GivenAContext())
.When(_ => WhenOcelotMiddlewareStartedCalled())
.Then(_ => ThenTheLogIs($"Ocelot.MiddlewareStarted: {_name}; {_downstreamContext.HttpContext.Request.Path}"))
.BDDfy();
}
[Fact]
public void should_trace_ocelot_middleware_finished()
{
this.Given(_ => GivenAMiddlewareName())
.And(_ => GivenAContext())
.When(_ => WhenOcelotMiddlewareFinishedCalled())
.Then(_ => ThenTheLogIs($"Ocelot.MiddlewareFinished: {_name}; {_downstreamContext.HttpContext.Request.Path}"))
.BDDfy();
}
[Fact]
public void should_trace_ocelot_middleware_exception()
{
this.Given(_ => GivenAMiddlewareName())
.And(_ => GivenAContext())
.And(_ => GivenAException(new Exception("oh no")))
.When(_ => WhenOcelotMiddlewareExceptionCalled())
.Then(_ => ThenTheLogIs($"Ocelot.MiddlewareException: {_name}; {_exception.Message};"))
.BDDfy();
}
[Fact]
public void should_trace_middleware_started()
{
this.Given(_ => GivenAMiddlewareName())
.And(_ => GivenAContext())
.When(_ => WhenMiddlewareStartedCalled())
.Then(_ => ThenTheLogIs($"MiddlewareStarting: {_name}; {_downstreamContext.HttpContext.Request.Path}"))
.Then(_ => ThenTheLogIs($"MiddlewareStarting: {_name}; {_httpContext.Request.Path}"))
.BDDfy();
}
@ -75,9 +43,8 @@ namespace Ocelot.UnitTests.Logging
public void should_trace_middleware_finished()
{
this.Given(_ => GivenAMiddlewareName())
.And(_ => GivenAContext())
.When(_ => WhenMiddlewareFinishedCalled())
.Then(_ => ThenTheLogIs($"MiddlewareFinished: {_name}; {_downstreamContext.HttpContext.Response.StatusCode}"))
.Then(_ => ThenTheLogIs($"MiddlewareFinished: {_name}; {_httpContext.Response.StatusCode}"))
.BDDfy();
}
@ -85,7 +52,6 @@ namespace Ocelot.UnitTests.Logging
public void should_trace_middleware_exception()
{
this.Given(_ => GivenAMiddlewareName())
.And(_ => GivenAContext())
.And(_ => GivenAException(new Exception("oh no")))
.When(_ => WhenMiddlewareExceptionCalled())
.Then(_ => ThenTheLogIs($"MiddlewareException: {_name}; {_exception.Message};"))
@ -97,29 +63,14 @@ namespace Ocelot.UnitTests.Logging
_exception = exception;
}
private void WhenOcelotMiddlewareStartedCalled()
{
_listener.OcelotMiddlewareStarted(_downstreamContext, _name);
}
private void WhenOcelotMiddlewareFinishedCalled()
{
_listener.OcelotMiddlewareFinished(_downstreamContext, _name);
}
private void WhenOcelotMiddlewareExceptionCalled()
{
_listener.OcelotMiddlewareException(_exception, _downstreamContext, _name);
}
private void WhenMiddlewareStartedCalled()
{
_listener.OnMiddlewareStarting(_downstreamContext.HttpContext, _name);
_listener.OnMiddlewareStarting(_httpContext, _name);
}
private void WhenMiddlewareFinishedCalled()
{
_listener.OnMiddlewareFinished(_downstreamContext.HttpContext, _name);
_listener.OnMiddlewareFinished(_httpContext, _name);
}
private void WhenMiddlewareExceptionCalled()
@ -127,11 +78,6 @@ namespace Ocelot.UnitTests.Logging
_listener.OnMiddlewareException(_exception, _name);
}
private void GivenAContext()
{
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
}
private void GivenAMiddlewareName()
{
_name = "name";