mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 14:23:34 +01:00
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using NFluent;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using WireMock.RequestBuilders;
|
|
using WireMock.ResponseBuilders;
|
|
using WireMock.Server;
|
|
using Xunit;
|
|
|
|
namespace WireMock.Net.Tests
|
|
{
|
|
public class FluentMockServerProxy2Tests
|
|
{
|
|
[Fact]
|
|
public async Task FluentMockServer_ProxyAndRecordSettings_ShouldProxy()
|
|
{
|
|
// Assign
|
|
var serverAsProxy = FluentMockServer.Start();
|
|
serverAsProxy.Given(Request.Create().UsingPost())
|
|
.RespondWith(Response.Create().WithStatusCode(201).WithBodyAsJson(new { p = 42 }).WithHeader("Content-Type", "application/json"));
|
|
|
|
// Act
|
|
var server = FluentMockServer.Start();
|
|
server.Given(Request.Create().UsingPost().WithHeader("prx", "1"))
|
|
.RespondWith(Response.Create().WithProxy(serverAsProxy.Urls[0]));
|
|
|
|
var request = new HttpRequestMessage
|
|
{
|
|
Method = HttpMethod.Post,
|
|
RequestUri = new Uri($"{server.Urls[0]}/TST"),
|
|
Content = new StringContent("test")
|
|
};
|
|
request.Headers.Add("prx", "1");
|
|
|
|
// Assert
|
|
var response = await new HttpClient().SendAsync(request);
|
|
string content = await response.Content.ReadAsStringAsync();
|
|
|
|
Check.That(content).IsEqualTo("{\"p\":42}");
|
|
Check.That(response.StatusCode).IsEqualTo(HttpStatusCode.Created);
|
|
Check.That(response.Content.Headers.GetValues("Content-Type").First()).IsEqualTo("application/json");
|
|
|
|
server.Dispose();
|
|
serverAsProxy.Dispose();
|
|
}
|
|
}
|
|
} |