mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 15:31:39 +02:00
* Fixed #133 * tests: add parametrised tests that cover various body matchers for json * Code review comments (BodyAsStringOriginal) * tests: minor method name change
This commit is contained in:
@@ -41,9 +41,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_Handlebars_UrlPathVerb()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("test {{request.url}} {{request.path}} {{request.method}}")
|
||||
@@ -60,9 +62,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_Handlebars_Query()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("test keya={{request.query.a}} idx={{request.query.a.[0]}} idx={{request.query.a.[1]}} keyb={{request.query.b}}")
|
||||
@@ -79,9 +83,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_Handlebars_Header()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
|
||||
|
||||
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}").WithBody("test").WithTransformer();
|
||||
|
||||
@@ -98,9 +104,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_Handlebars_Headers()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
|
||||
|
||||
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}", "{{request.url}}").WithBody("test").WithTransformer();
|
||||
|
||||
@@ -118,9 +126,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_Handlebars_Origin_Port_Protocol_Host()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost:1234"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost:1234"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("test {{request.origin}} {{request.port}} {{request.protocol}} {{request.host}}")
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
@@ -15,9 +16,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_Bytes_Encoding_Destination_String()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.String, Encoding.ASCII);
|
||||
|
||||
@@ -34,9 +37,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_Bytes_Encoding_Destination_Bytes()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.SameAsSource, Encoding.ASCII);
|
||||
|
||||
@@ -53,9 +58,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_String_Encoding()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create().WithBody("test", null, Encoding.ASCII);
|
||||
|
||||
@@ -71,9 +78,11 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_Object_Encoding()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
object x = new { value = "test" };
|
||||
var response = Response.Create().WithBodyAsJson(x, Encoding.ASCII);
|
||||
@@ -137,7 +146,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
// Assert
|
||||
Check.That(responseMessage.Body).IsNull();
|
||||
Check.That(responseMessage.BodyAsBytes).IsNull();
|
||||
Check.That(((dynamic) responseMessage.BodyAsJson).value).Equals(42);
|
||||
Check.That(((dynamic)responseMessage.BodyAsJson).value).Equals(42);
|
||||
Check.That(responseMessage.BodyEncoding).Equals(Encoding.ASCII);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user