mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-24 18:11:10 +01:00
fix (#461)
This commit is contained in:
@@ -16,6 +16,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
{
|
||||
public class ResponseWithProxyTests : IDisposable
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
|
||||
private readonly WireMockServer _server;
|
||||
private readonly Guid _guid;
|
||||
@@ -27,21 +28,32 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
_server = WireMockServer.Start();
|
||||
_server.Given(Request.Create().UsingPost().WithPath($"/{_guid}"))
|
||||
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 42 }).WithHeader("Content-Type", "application/json"));
|
||||
_server.Given(Request.Create().UsingPost().WithPath($"/{_guid}/append"))
|
||||
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 10 }).WithHeader("Content-Type", "application/json"));
|
||||
_server.Given(Request.Create().UsingPost().WithPath($"/prepend/{_guid}"))
|
||||
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 11 }).WithHeader("Content-Type", "application/json"));
|
||||
_server.Given(Request.Create().UsingPost().WithPath($"/prepend/{_guid}/append"))
|
||||
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 12 }).WithHeader("Content-Type", "application/json"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Response_WithProxy()
|
||||
[Theory]
|
||||
[InlineData("", "", "{\"p\":42}")]
|
||||
[InlineData("", "/append", "{\"p\":10}")]
|
||||
[InlineData("/prepend", "", "{\"p\":11}")]
|
||||
[InlineData("/prepend", "/append", "{\"p\":12}")]
|
||||
public async Task Response_WithProxy(string prepend, string append, string expectedBody)
|
||||
{
|
||||
// Assign
|
||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
|
||||
var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}/{_guid}"), "POST", "::1", new BodyData { DetectedBodyType = BodyType.Json, BodyAsJson = new { a = 1 } }, headers);
|
||||
var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}{prepend}/{_guid}{append}"), "POST", ClientIp, new BodyData { DetectedBodyType = BodyType.Json, BodyAsJson = new { a = 1 } }, headers);
|
||||
var response = Response.Create().WithProxy(_server.Urls[0]);
|
||||
|
||||
// Act
|
||||
var responseMessage = await response.ProvideResponseAsync(request, _settings);
|
||||
|
||||
// Assert
|
||||
Check.That(responseMessage.BodyData.BodyAsString).IsEqualTo("{\"p\":42}");
|
||||
Check.That(request.ProxyUrl).IsNotNull();
|
||||
Check.That(responseMessage.BodyData.BodyAsString).IsEqualTo(expectedBody);
|
||||
Check.That(responseMessage.StatusCode).IsEqualTo(201);
|
||||
Check.That(responseMessage.Headers["Content-Type"].ToString()).IsEqualTo("application/json");
|
||||
}
|
||||
@@ -63,7 +75,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
var response = Response.Create().WithProxy(settings);
|
||||
|
||||
// Act
|
||||
var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}/{_guid}"), "GET", "::1");
|
||||
var request = new RequestMessage(new UrlDetails($"{_server.Urls[0]}/{_guid}"), "GET", ClientIp);
|
||||
|
||||
Check.ThatAsyncCode(() => response.ProvideResponseAsync(request, _settings)).Throws<HttpRequestException>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user