mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-27 05:12:50 +08:00

* started messing around with this on the train last night * mega hacking away to change middleware into Ocelot iddleware * scoped data repo back in * broken commit getting tests working * another broken commit farting around with tests * all unit tests passing again * mw pipeline for ocelot...still loads of hacks but getting there now to get acceptance tests working, then fix config so you can have aggregate and then imlement multiplexer, then mapping to response...loads to do * all tests passing before aggregation feature implemented * removed all the request middleware stuff we dont need it * updated how errors work...tho i think there could be edge case here when aggregating because one downstream could error and this would effect another * removed multiplexer so you dont have to send route down, this isnt very thread safe...sigh * hacking around getting the config for aggregates in, this might change * refactored builder and unit tests passing now * Updated a bunch of ports for tests * plugged in code to create reroutes that are aggregates * made multiplexer a class * hacked test to death * simple aggregator done, initial validation done * removed request id from context, it is still specific for http request * now aggregates to json always * docs for aggregate reroutes * Updated docs
70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Moq;
|
|
using Ocelot.Configuration;
|
|
using Ocelot.Configuration.Builder;
|
|
using Ocelot.Middleware;
|
|
using Ocelot.Middleware.Multiplexer;
|
|
using Shouldly;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
namespace Ocelot.UnitTests.Middleware
|
|
{
|
|
public class MultiplexerTests
|
|
{
|
|
private readonly Multiplexer _multiplexer;
|
|
private readonly DownstreamContext _context;
|
|
private ReRoute _reRoute;
|
|
private readonly OcelotRequestDelegate _pipeline;
|
|
private int _count;
|
|
private Mock<IResponseAggregator> _aggregator;
|
|
|
|
public MultiplexerTests()
|
|
{
|
|
_aggregator = new Mock<IResponseAggregator>();
|
|
_context = new DownstreamContext(new DefaultHttpContext());
|
|
_pipeline = async context => { _count++; };
|
|
_multiplexer = new Multiplexer(_aggregator.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public void should_multiplex()
|
|
{
|
|
var reRoute = new ReRouteBuilder().WithDownstreamReRoute(new DownstreamReRouteBuilder().Build()).WithDownstreamReRoute(new DownstreamReRouteBuilder().Build()).Build();
|
|
|
|
this.Given(x => GivenTheFollowing(reRoute))
|
|
.When(x => WhenIMultiplex())
|
|
.Then(x => ThePipelineIsCalled(2))
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_not_multiplex()
|
|
{
|
|
var reRoute = new ReRouteBuilder().WithDownstreamReRoute(new DownstreamReRouteBuilder().Build()).Build();
|
|
|
|
this.Given(x => GivenTheFollowing(reRoute))
|
|
.When(x => WhenIMultiplex())
|
|
.Then(x => ThePipelineIsCalled(1))
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenTheFollowing(ReRoute reRoute)
|
|
{
|
|
_reRoute = reRoute;
|
|
}
|
|
|
|
private void WhenIMultiplex()
|
|
{
|
|
_multiplexer.Multiplex(_context, _reRoute, _pipeline).GetAwaiter().GetResult();
|
|
|
|
}
|
|
|
|
private void ThePipelineIsCalled(int expected)
|
|
{
|
|
_count.ShouldBe(expected);
|
|
}
|
|
}
|
|
}
|