Feature/another look at logging (#303)

* #212 - hacked websockets proxy together

* faffing around

* #212 hacking away :(

* #212 websockets proxy middleware working

* #212 map when for webockets working

* #212 some test refactor

* #212 temp commit

* #212 websockets proxy working, tests passing...need to do some tidying and write docs

* #212 more code coverage

* #212 docs for websockets

* #212 updated readme

* #212 tidying up after websockets refactoring

* #212 tidying up after websockets refactoring

* #212 tidying up after websockets refactoring

* changing logging levels and logging like ms reccomends with structured data rather than strings

* more faffing

* more fafin

* #287 ocelot logger now only takes strings as it did take params then just turned them to strings, misleading, unit tests for logger and diagnosticlogger

* #287 errors now logged as they happen

* #287 more detail for logs requested in issue

* #287 tidy up

* #287 renamed

* #287 always log context id

* #287 fixed me being an idiot

* #287 removed crap websockets unit test that isnt a unit test

* #287 removed crap websockets unit test that isnt a unit test
This commit is contained in:
Tom Pallister
2018-04-07 12:03:24 +01:00
committed by GitHub
parent 0c380239a9
commit efbb950ea2
60 changed files with 600 additions and 387 deletions

View File

@ -1,5 +1,3 @@
using Ocelot.Middleware;
namespace Ocelot.UnitTests.Errors
{
using System;
@ -15,18 +13,18 @@ namespace Ocelot.UnitTests.Errors
using Moq;
using Ocelot.Configuration;
using Ocelot.Errors;
using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.Infrastructure.RequestData;
using Ocelot.Middleware;
public class ExceptionHandlerMiddlewareTests
{
bool _shouldThrowAnException = false;
private Mock<IOcelotConfigurationProvider> _provider;
private Mock<IRequestScopedDataRepository> _repo;
bool _shouldThrowAnException;
private readonly Mock<IOcelotConfigurationProvider> _provider;
private readonly Mock<IRequestScopedDataRepository> _repo;
private Mock<IOcelotLoggerFactory> _loggerFactory;
private Mock<IOcelotLogger> _logger;
private ExceptionHandlerMiddleware _middleware;
private DownstreamContext _downstreamContext;
private readonly ExceptionHandlerMiddleware _middleware;
private readonly DownstreamContext _downstreamContext;
private OcelotRequestDelegate _next;
public ExceptionHandlerMiddlewareTests()
@ -59,7 +57,7 @@ namespace Ocelot.UnitTests.Errors
.And(_ => GivenTheConfigurationIs(config))
.When(_ => WhenICallTheMiddleware())
.Then(_ => ThenTheResponseIsOk())
.And(_ => TheRequestIdIsNotSet())
.And(_ => TheAspDotnetRequestIdIsSet())
.BDDfy();
}
@ -89,7 +87,7 @@ namespace Ocelot.UnitTests.Errors
}
[Fact]
public void ShouldNotSetRequestId()
public void ShouldSetAspDotNetRequestId()
{
var config = new OcelotConfiguration(null, null, null, null);
@ -97,7 +95,7 @@ namespace Ocelot.UnitTests.Errors
.And(_ => GivenTheConfigurationIs(config))
.When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234"))
.Then(_ => ThenTheResponseIsOk())
.And(_ => TheRequestIdIsNotSet())
.And(_ => TheAspDotnetRequestIdIsSet())
.BDDfy();
}
@ -146,29 +144,19 @@ namespace Ocelot.UnitTests.Errors
private void GivenTheConfigReturnsError()
{
var config = new OcelotConfiguration(null, null, null, null);
var response = new Ocelot.Responses.ErrorResponse<IOcelotConfiguration>(new FakeError());
var response = new Responses.ErrorResponse<IOcelotConfiguration>(new FakeError());
_provider
.Setup(x => x.Get()).ReturnsAsync(response);
}
public class FakeError : Error
{
public FakeError()
: base("meh", OcelotErrorCode.CannotAddDataError)
{
}
}
private void TheRequestIdIsSet(string key, string value)
{
_repo.Verify(x => x.Add<string>(key, value), Times.Once);
_repo.Verify(x => x.Add(key, value), Times.Once);
}
private void GivenTheConfigurationIs(IOcelotConfiguration config)
{
var response = new Ocelot.Responses.OkResponse<IOcelotConfiguration>(config);
var response = new Responses.OkResponse<IOcelotConfiguration>(config);
_provider
.Setup(x => x.Get()).ReturnsAsync(response);
}
@ -193,9 +181,17 @@ namespace Ocelot.UnitTests.Errors
_downstreamContext.HttpContext.Response.StatusCode.ShouldBe(500);
}
private void TheRequestIdIsNotSet()
private void TheAspDotnetRequestIdIsSet()
{
_repo.Verify(x => x.Add<string>(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_repo.Verify(x => x.Add(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
class FakeError : Error
{
internal FakeError()
: base("meh", OcelotErrorCode.CannotAddDataError)
{
}
}
}
}