mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-26 11:42:50 +08:00

* test for issue * added service fabric sample * working!! * changed sample naming to Ocelot * removed files we dont need * removed files we dont need * updated sample gitignore * updated sample gitignore * getting ocelot to work with service fabric using the reverse proxy * #238 - added support for service fabric discovery provider, proxies requests through naming service, wont work on partioned service fabric services yet * #238 - Manually tested service fabric using sample..all seems OK. Made some changes after testing, added docs * #238 - added docs for servic fabric
113 lines
4.2 KiB
C#
113 lines
4.2 KiB
C#
using System.Linq;
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
namespace Ocelot.AcceptanceTests
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Ocelot.Configuration.File;
|
|
using Shouldly;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
public class ServiceFabricTests : IDisposable
|
|
{
|
|
private IWebHost _builder;
|
|
private readonly Steps _steps;
|
|
private string _downstreamPath;
|
|
|
|
public ServiceFabricTests()
|
|
{
|
|
_steps = new Steps();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_support_service_fabric_naming_and_dns_service()
|
|
{
|
|
var configuration = new FileConfiguration
|
|
{
|
|
ReRoutes = new List<FileReRoute>
|
|
{
|
|
new FileReRoute
|
|
{
|
|
DownstreamPathTemplate = "/api/values",
|
|
DownstreamScheme = "http",
|
|
UpstreamPathTemplate = "/EquipmentInterfaces",
|
|
UpstreamHttpMethod = new List<string> { "Get" },
|
|
UseServiceDiscovery = true,
|
|
ServiceName = "OcelotServiceApplication/OcelotApplicationService"
|
|
}
|
|
},
|
|
GlobalConfiguration = new FileGlobalConfiguration
|
|
{
|
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
|
{
|
|
Host = "localhost",
|
|
Port = 19081,
|
|
Type = "ServiceFabric"
|
|
}
|
|
}
|
|
};
|
|
|
|
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura"))
|
|
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
|
.And(x => _steps.GivenOcelotIsRunning())
|
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces"))
|
|
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
|
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
|
|
{
|
|
_builder = new WebHostBuilder()
|
|
.UseUrls(baseUrl)
|
|
.UseKestrel()
|
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
.UseIISIntegration()
|
|
.Configure(app =>
|
|
{
|
|
app.UsePathBase(basePath);
|
|
app.Run(async context =>
|
|
{
|
|
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
|
|
|
if(_downstreamPath != basePath)
|
|
{
|
|
context.Response.StatusCode = statusCode;
|
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
|
}
|
|
else
|
|
{
|
|
if (context.Request.Query.TryGetValue("cmd", out var values))
|
|
{
|
|
values.First().ShouldBe("instance");
|
|
context.Response.StatusCode = statusCode;
|
|
await context.Response.WriteAsync(responseBody);
|
|
}
|
|
else
|
|
{
|
|
context.Response.StatusCode = statusCode;
|
|
await context.Response.WriteAsync("downstream path didnt match base path");
|
|
}
|
|
}
|
|
});
|
|
})
|
|
.Build();
|
|
|
|
_builder.Start();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_builder?.Dispose();
|
|
_steps.Dispose();
|
|
}
|
|
}
|
|
}
|