BodyAsJson (#80)

This commit is contained in:
Stef Heyenrath
2018-01-31 12:41:10 +01:00
parent cdcaaa970a
commit 40ff8514ac
5 changed files with 97 additions and 22 deletions

View File

@@ -17,7 +17,7 @@ namespace WireMock.Net.Tests
private FluentMockServer _serverForProxyForwarding;
[Fact]
public async Task FluentMockServer_Should_proxy_responses()
public async Task FluentMockServer_Proxy_Should_proxy_responses()
{
// given
_server = FluentMockServer.Start();
@@ -33,7 +33,7 @@ namespace WireMock.Net.Tests
}
[Fact]
public async Task FluentMockServer_Should_preserve_content_header_in_proxied_request()
public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxied_request()
{
// given
_serverForProxyForwarding = FluentMockServer.Start();
@@ -64,7 +64,7 @@ namespace WireMock.Net.Tests
}
[Fact]
public async Task FluentMockServer_Should_preserve_content_header_in_proxied_request_with_empty_content()
public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxied_request_with_empty_content()
{
// given
_serverForProxyForwarding = FluentMockServer.Start();
@@ -95,7 +95,7 @@ namespace WireMock.Net.Tests
}
[Fact]
public async Task FluentMockServer_Should_preserve_content_header_in_proxied_response()
public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxied_response()
{
// given
_serverForProxyForwarding = FluentMockServer.Start();
@@ -125,7 +125,7 @@ namespace WireMock.Net.Tests
}
[Fact]
public async Task FluentMockServer_Should_change_absolute_location_header_in_proxied_response()
public async Task FluentMockServer_Proxy_Should_change_absolute_location_header_in_proxied_response()
{
// given
_serverForProxyForwarding = FluentMockServer.Start();
@@ -155,7 +155,7 @@ namespace WireMock.Net.Tests
}
[Fact]
public async Task FluentMockServer_Should_preserve_cookie_header_in_proxied_request()
public async Task FluentMockServer_Proxy_Should_preserve_cookie_header_in_proxied_request()
{
// given
_serverForProxyForwarding = FluentMockServer.Start();
@@ -184,5 +184,35 @@ namespace WireMock.Net.Tests
Check.That(receivedRequest.Cookies).IsNotNull();
Check.That(receivedRequest.Cookies).ContainsPair("name", "value");
}
[Fact]
public async Task FluentMockServer_Proxy_Should_set_BodyAsJson_in_proxied_response()
{
// Assign
_serverForProxyForwarding = FluentMockServer.Start();
_serverForProxyForwarding
.Given(Request.Create().WithPath("/*"))
.RespondWith(Response.Create()
.WithBodyAsJson(new { i = 42 })
.WithHeader("Content-Type", "application/json; charset=utf-8"));
_server = FluentMockServer.Start();
_server
.Given(Request.Create().WithPath("/*"))
.RespondWith(Response.Create().WithProxy(_serverForProxyForwarding.Urls[0]));
// Act
var requestMessage = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(_server.Urls[0])
};
var response = await new HttpClient().SendAsync(requestMessage);
// Assert
string content = await response.Content.ReadAsStringAsync();
Check.That(content).IsEqualTo("{\"i\":42}");
Check.That(response.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
}
}
}