mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:18:17 +08:00
* #298 initial hacking around better aggregation * #298 bit more hacking around * #298 abstraction over httpresponsemessage * #298 tidying up * #298 docs * #298 missed this
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.Middleware;
|
||||
|
||||
namespace Ocelot.UnitTests.Cache
|
||||
namespace Ocelot.UnitTests.Cache
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@ -17,15 +14,17 @@ namespace Ocelot.UnitTests.Cache
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
public class OutputCacheMiddlewareRealCacheTests
|
||||
{
|
||||
private IOcelotCache<CachedResponse> _cacheManager;
|
||||
private OutputCacheMiddleware _middleware;
|
||||
private DownstreamContext _downstreamContext;
|
||||
private readonly IOcelotCache<CachedResponse> _cacheManager;
|
||||
private readonly OutputCacheMiddleware _middleware;
|
||||
private readonly DownstreamContext _downstreamContext;
|
||||
private OcelotRequestDelegate _next;
|
||||
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
||||
private IRegionCreator _regionCreator;
|
||||
@ -56,14 +55,10 @@ namespace Ocelot.UnitTests.Cache
|
||||
Headers = { ContentType = new MediaTypeHeaderValue("application/json")}
|
||||
};
|
||||
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
var response = new DownstreamResponse(content, HttpStatusCode.OK, new List<KeyValuePair<string, IEnumerable<string>>>());
|
||||
|
||||
this.Given(x => x.GivenResponseIsNotCached(response))
|
||||
.And(x => x.GivenTheDownstreamRouteIs())
|
||||
.And(x => x.GivenThereAreNoErrors())
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheContentTypeHeaderIsCached())
|
||||
.BDDfy();
|
||||
@ -81,9 +76,9 @@ namespace Ocelot.UnitTests.Cache
|
||||
header.First().ShouldBe("application/json");
|
||||
}
|
||||
|
||||
private void GivenResponseIsNotCached(HttpResponseMessage message)
|
||||
private void GivenResponseIsNotCached(DownstreamResponse response)
|
||||
{
|
||||
_downstreamContext.DownstreamResponse = message;
|
||||
_downstreamContext.DownstreamResponse = response;
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamRouteIs()
|
||||
@ -96,10 +91,5 @@ namespace Ocelot.UnitTests.Cache
|
||||
|
||||
_downstreamContext.DownstreamReRoute = reRoute;
|
||||
}
|
||||
|
||||
private void GivenThereAreNoErrors()
|
||||
{
|
||||
_downstreamContext.Errors = new List<Error>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System.Net;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.Middleware;
|
||||
|
||||
namespace Ocelot.UnitTests.Cache
|
||||
namespace Ocelot.UnitTests.Cache
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -19,17 +15,20 @@ namespace Ocelot.UnitTests.Cache
|
||||
using Ocelot.Logging;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
using System.Net;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
public class OutputCacheMiddlewareTests
|
||||
{
|
||||
private readonly Mock<IOcelotCache<CachedResponse>> _cacheManager;
|
||||
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
||||
private readonly Mock<IOcelotLoggerFactory> _loggerFactory;
|
||||
private Mock<IOcelotLogger> _logger;
|
||||
private OutputCacheMiddleware _middleware;
|
||||
private DownstreamContext _downstreamContext;
|
||||
private OcelotRequestDelegate _next;
|
||||
private readonly DownstreamContext _downstreamContext;
|
||||
private readonly OcelotRequestDelegate _next;
|
||||
private CachedResponse _response;
|
||||
private IRegionCreator _regionCreator;
|
||||
private readonly IRegionCreator _regionCreator;
|
||||
|
||||
public OutputCacheMiddlewareTests()
|
||||
{
|
||||
@ -46,7 +45,17 @@ namespace Ocelot.UnitTests.Cache
|
||||
[Fact]
|
||||
public void should_returned_cached_item_when_it_is_in_cache()
|
||||
{
|
||||
var cachedResponse = new CachedResponse(HttpStatusCode.OK, new Dictionary<string, IEnumerable<string>>(), "", new Dictionary<string, IEnumerable<string>>());
|
||||
var headers = new Dictionary<string, IEnumerable<string>>
|
||||
{
|
||||
{ "test", new List<string> { "test" } }
|
||||
};
|
||||
|
||||
var contentHeaders = new Dictionary<string, IEnumerable<string>>
|
||||
{
|
||||
{ "content-type", new List<string> { "application/json" } }
|
||||
};
|
||||
|
||||
var cachedResponse = new CachedResponse(HttpStatusCode.OK, headers, "", contentHeaders);
|
||||
this.Given(x => x.GivenThereIsACachedResponse(cachedResponse))
|
||||
.And(x => x.GivenTheDownstreamRouteIs())
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
@ -59,7 +68,6 @@ namespace Ocelot.UnitTests.Cache
|
||||
{
|
||||
this.Given(x => x.GivenResponseIsNotCached())
|
||||
.And(x => x.GivenTheDownstreamRouteIs())
|
||||
.And(x => x.GivenThereAreNoErrors())
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheCacheAddIsCalledCorrectly())
|
||||
.BDDfy();
|
||||
@ -81,7 +89,7 @@ namespace Ocelot.UnitTests.Cache
|
||||
|
||||
private void GivenResponseIsNotCached()
|
||||
{
|
||||
_downstreamContext.DownstreamResponse = new HttpResponseMessage();
|
||||
_downstreamContext.DownstreamResponse = new DownstreamResponse(new HttpResponseMessage());
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamRouteIs()
|
||||
@ -101,11 +109,6 @@ namespace Ocelot.UnitTests.Cache
|
||||
_downstreamContext.DownstreamReRoute = downstreamRoute.ReRoute.DownstreamReRoute[0];
|
||||
}
|
||||
|
||||
private void GivenThereAreNoErrors()
|
||||
{
|
||||
_downstreamContext.Errors = new List<Error>();
|
||||
}
|
||||
|
||||
private void ThenTheCacheGetIsCalledCorrectly()
|
||||
{
|
||||
_cacheManager
|
||||
|
Reference in New Issue
Block a user