mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-20 00:42:51 +08:00
71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
namespace Ocelot.AcceptanceTests
|
|
{
|
|
using Ocelot.Configuration.File;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
public class ResponseCodeTests : IDisposable
|
|
{
|
|
private readonly Steps _steps;
|
|
private readonly ServiceHandler _serviceHandler;
|
|
|
|
public ResponseCodeTests()
|
|
{
|
|
_serviceHandler = new ServiceHandler();
|
|
_steps = new Steps();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_response_304_when_service_returns_304()
|
|
{
|
|
var port = RandomPortFinder.GetRandomPort();
|
|
|
|
var configuration = new FileConfiguration
|
|
{
|
|
Routes = new List<FileRoute>
|
|
{
|
|
new FileRoute
|
|
{
|
|
DownstreamPathTemplate = "/{everything}",
|
|
DownstreamScheme = "http",
|
|
DownstreamHostAndPorts = new List<FileHostAndPort>
|
|
{
|
|
new FileHostAndPort
|
|
{
|
|
Host = "localhost",
|
|
Port = port,
|
|
}
|
|
},
|
|
UpstreamPathTemplate = "/{everything}",
|
|
UpstreamHttpMethod = new List<string> { "Get" },
|
|
}
|
|
}
|
|
};
|
|
|
|
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/inline.132.bundle.js", 304))
|
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
|
.And(x => _steps.GivenOcelotIsRunning())
|
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/inline.132.bundle.js"))
|
|
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotModified))
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode)
|
|
{
|
|
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
|
{
|
|
context.Response.StatusCode = statusCode;
|
|
});
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_serviceHandler?.Dispose();
|
|
_steps.Dispose();
|
|
}
|
|
}
|
|
}
|