mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-05-01 09:52:50 +08:00

* #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
86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using Ocelot.Middleware;
|
|
|
|
namespace Ocelot.UnitTests.Responder
|
|
{
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using Ocelot.DownstreamRouteFinder.Finder;
|
|
using Ocelot.Errors;
|
|
using Ocelot.Logging;
|
|
using Ocelot.Responder;
|
|
using Ocelot.Responder.Middleware;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
public class ResponderMiddlewareTests
|
|
{
|
|
private readonly Mock<IHttpResponder> _responder;
|
|
private readonly Mock<IErrorsToHttpStatusCodeMapper> _codeMapper;
|
|
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
|
private Mock<IOcelotLogger> _logger;
|
|
private readonly ResponderMiddleware _middleware;
|
|
private readonly DownstreamContext _downstreamContext;
|
|
private OcelotRequestDelegate _next;
|
|
|
|
public ResponderMiddlewareTests()
|
|
{
|
|
_responder = new Mock<IHttpResponder>();
|
|
_codeMapper = new Mock<IErrorsToHttpStatusCodeMapper>();
|
|
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
|
|
_loggerFactory = new Mock<IOcelotLoggerFactory>();
|
|
_logger = new Mock<IOcelotLogger>();
|
|
_loggerFactory.Setup(x => x.CreateLogger<ResponderMiddleware>()).Returns(_logger.Object);
|
|
_next = context => Task.CompletedTask;
|
|
_middleware = new ResponderMiddleware(_next, _responder.Object, _loggerFactory.Object, _codeMapper.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public void should_not_return_any_errors()
|
|
{
|
|
this.Given(x => x.GivenTheHttpResponseMessageIs(new HttpResponseMessage()))
|
|
.And(x => x.GivenThereAreNoPipelineErrors())
|
|
.When(x => x.WhenICallTheMiddleware())
|
|
.Then(x => x.ThenThereAreNoErrors())
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_any_errors()
|
|
{
|
|
this.Given(x => x.GivenTheHttpResponseMessageIs(new HttpResponseMessage()))
|
|
.And(x => x.GivenThereArePipelineErrors(new UnableToFindDownstreamRouteError("/path", "GET")))
|
|
.When(x => x.WhenICallTheMiddleware())
|
|
.Then(x => x.ThenThereAreNoErrors())
|
|
.BDDfy();
|
|
}
|
|
|
|
private void WhenICallTheMiddleware()
|
|
{
|
|
_middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
|
|
}
|
|
|
|
private void GivenTheHttpResponseMessageIs(HttpResponseMessage response)
|
|
{
|
|
_downstreamContext.DownstreamResponse = response;
|
|
}
|
|
|
|
private void GivenThereAreNoPipelineErrors()
|
|
{
|
|
_downstreamContext.Errors = new List<Error>();
|
|
}
|
|
|
|
private void ThenThereAreNoErrors()
|
|
{
|
|
//todo a better assert?
|
|
}
|
|
|
|
private void GivenThereArePipelineErrors(Error error)
|
|
{
|
|
_downstreamContext.Errors = new List<Error>(){error};
|
|
}
|
|
}
|
|
}
|