first acceptance test failing..

This commit is contained in:
Tom Gardham-Pallister 2017-06-27 19:07:55 +01:00
parent e4e7fcc943
commit 0fa759c76c
4 changed files with 74 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ocelot.Configuration.Provider; using Ocelot.Configuration.Provider;
using Ocelot.Logging; using Ocelot.Logging;
@ -33,9 +34,11 @@ namespace Ocelot.Cache
return new List<string>(); return new List<string>();
} }
var cachedReRoutes = config.Data.ReRoutes.Where(x => x.IsCached);
var regions = new List<string>(); var regions = new List<string>();
foreach(var reRoute in config.Data.ReRoutes) foreach(var reRoute in cachedReRoutes)
{ {
var region = _creator.Region(reRoute); var region = _creator.Region(reRoute);
regions.Add(region); regions.Add(region);

View File

@ -7,7 +7,7 @@ using Ocelot.Configuration.Provider;
namespace Ocelot.Controllers namespace Ocelot.Controllers
{ {
[Authorize] [Authorize]
[Route("cache")] [Route("outputcache")]
public class OutputCacheController : Controller public class OutputCacheController : Controller
{ {
private IOcelotCache<HttpResponseMessage> _cache; private IOcelotCache<HttpResponseMessage> _cache;

View File

@ -218,6 +218,63 @@ namespace Ocelot.IntegrationTests
.BDDfy(); .BDDfy();
} }
[Fact]
public void should_return_regions()
{
var initialConfiguration = new FileConfiguration
{
GlobalConfiguration = new FileGlobalConfiguration
{
AdministrationPath = "/administration"
},
ReRoutes = new List<FileReRoute>()
{
new FileReRoute()
{
DownstreamHost = "localhost",
DownstreamPort = 80,
DownstreamScheme = "https",
DownstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "get" },
UpstreamPathTemplate = "/",
FileCacheOptions = new FileCacheOptions
{
TtlSeconds = 10
}
},
new FileReRoute()
{
DownstreamHost = "localhost",
DownstreamPort = 80,
DownstreamScheme = "https",
DownstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "get" },
UpstreamPathTemplate = "/test",
FileCacheOptions = new FileCacheOptions
{
TtlSeconds = 10
}
}
}
};
var expected = new List<string>
{
"get /",
"get /test"
};
this.Given(x => GivenThereIsAConfiguration(initialConfiguration))
.And(x => GivenOcelotIsRunning())
.And(x => GivenIHaveAnOcelotToken("/administration"))
.And(x => GivenIHaveAddedATokenToMyRequest())
.When(x => WhenIGetUrlOnTheApiGateway("/administration/outputcache"))
.Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => ThenTheResponseShouldBe(expected))
.BDDfy();
}
private void GivenAnotherOcelotIsRunning(string baseUrl) private void GivenAnotherOcelotIsRunning(string baseUrl)
{ {
_httpClientTwo.BaseAddress = new Uri(baseUrl); _httpClientTwo.BaseAddress = new Uri(baseUrl);
@ -256,6 +313,13 @@ namespace Ocelot.IntegrationTests
_response = _httpClient.PostAsync(url, content).Result; _response = _httpClient.PostAsync(url, content).Result;
} }
private void ThenTheResponseShouldBe(List<string> expected)
{
var content = _response.Content.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<List<string>>(content);
result.ShouldBe(expected);
}
private void ThenTheResponseShouldBe(FileConfiguration expected) private void ThenTheResponseShouldBe(FileConfiguration expected)
{ {
var response = JsonConvert.DeserializeObject<FileConfiguration>(_response.Content.ReadAsStringAsync().Result); var response = JsonConvert.DeserializeObject<FileConfiguration>(_response.Content.ReadAsStringAsync().Result);

View File

@ -38,9 +38,13 @@ namespace Ocelot.UnitTests.Cache
[Fact] [Fact]
public void should_get_regions() public void should_get_regions()
{ {
var cacheOptions = new CacheOptions(12);
var reRoute = new ReRouteBuilder() var reRoute = new ReRouteBuilder()
.WithUpstreamHttpMethod(new List<string>{"Get"}) .WithUpstreamHttpMethod(new List<string>{"Get"})
.WithUpstreamPathTemplate("/") .WithUpstreamPathTemplate("/")
.WithCacheOptions(cacheOptions)
.WithIsCached(true)
.Build(); .Build();
var reRoutes = new List<ReRoute> var reRoutes = new List<ReRoute>
@ -62,7 +66,7 @@ namespace Ocelot.UnitTests.Cache
.BDDfy(); .BDDfy();
} }
[Fact] [Fact]
public void should_return_empty_regions() public void should_return_empty_regions()
{ {
var expected = new List<string>(); var expected = new List<string>();