Body Encoding - admin interface

This commit is contained in:
Sebastian Bebrys
2017-02-23 14:45:43 +01:00
parent c38373eb1f
commit 6513ac9de8
11 changed files with 134 additions and 59 deletions

View File

@@ -0,0 +1,23 @@
using System.Text;
namespace WireMock.Admin.Mappings
{
/// <summary>
/// EncodingModel
/// </summary>
public class EncodingModel
{
/// <summary>
/// Encoding CodePage
/// </summary>
public int CodePage { get; set; }
/// <summary>
/// Encoding EncodingName
/// </summary>
public string EncodingName { get; set; }
/// <summary>
/// Encoding WebName
/// </summary>
public string WebName { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace WireMock.Admin.Mappings namespace WireMock.Admin.Mappings
{ {
@@ -39,6 +40,14 @@ namespace WireMock.Admin.Mappings
/// </value> /// </value>
public object BodyAsJson { get; set; } public object BodyAsJson { get; set; }
/// <summary>
/// Gets or sets the body encoding.
/// </summary>
/// <value>
/// The body encoding.
/// </value>
public EncodingModel BodyEncoding { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether [use transformer]. /// Gets or sets a value indicating whether [use transformer].
/// </summary> /// </summary>

View File

@@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using WireMock.Admin.Mappings;
using WireMock.Util; using WireMock.Util;
namespace WireMock.Admin.Requests namespace WireMock.Admin.Requests
@@ -66,5 +68,13 @@ namespace WireMock.Admin.Requests
/// The body. /// The body.
/// </value> /// </value>
public string Body { get; set; } public string Body { get; set; }
/// <summary>
/// Gets or sets the body encoding.
/// </summary>
/// <value>
/// The body encoding.
/// </value>
public EncodingModel BodyEncoding { get; set; }
} }
} }

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using WireMock.Admin.Mappings;
namespace WireMock.Admin.Requests namespace WireMock.Admin.Requests
{ {
@@ -26,5 +28,10 @@ namespace WireMock.Admin.Requests
/// Gets or sets the original body. /// Gets or sets the original body.
/// </summary> /// </summary>
public string BodyOriginal { get; set; } public string BodyOriginal { get; set; }
/// <summary>
/// Gets or sets the body.
/// </summary>
public EncodingModel BodyEncoding { get; set; }
} }
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text;
namespace WireMock namespace WireMock
{ {
@@ -18,11 +19,11 @@ namespace WireMock
/// <returns>The <see cref="RequestMessage"/>.</returns> /// <returns>The <see cref="RequestMessage"/>.</returns>
public RequestMessage Map(HttpListenerRequest listenerRequest) public RequestMessage Map(HttpListenerRequest listenerRequest)
{ {
var url = listenerRequest.Url; Uri url = listenerRequest.Url;
var verb = listenerRequest.HttpMethod; string verb = listenerRequest.HttpMethod;
var body = GetRequestBody(listenerRequest); byte[] body = GetRequestBody(listenerRequest);
var bodyEncoding = body != null ? listenerRequest.ContentEncoding : null; Encoding bodyEncoding = body != null ? listenerRequest.ContentEncoding : null;
var bodyAsString = bodyEncoding?.GetString(body); string bodyAsString = bodyEncoding?.GetString(body);
var listenerHeaders = listenerRequest.Headers; var listenerHeaders = listenerRequest.Headers;
var headers = listenerHeaders.AllKeys.ToDictionary(k => k, k => listenerHeaders[k]); var headers = listenerHeaders.AllKeys.ToDictionary(k => k, k => listenerHeaders[k]);
var cookies = new Dictionary<string, string>(); var cookies = new Dictionary<string, string>();

View File

@@ -28,7 +28,7 @@ namespace WireMock
return; return;
var encoding = responseMessage.BodyEncoding ?? _utf8NoBom; var encoding = responseMessage.BodyEncoding ?? _utf8NoBom;
var buffer = encoding.GetBytes(responseMessage.Body); byte[] buffer = encoding.GetBytes(responseMessage.Body);
listenerResponse.ContentEncoding = encoding; listenerResponse.ContentEncoding = encoding;
listenerResponse.ContentLength64 = buffer.Length; listenerResponse.ContentLength64 = buffer.Length;

View File

@@ -165,7 +165,7 @@ namespace WireMock.ResponseBuilders
{ {
Check.NotNull(body, nameof(body)); Check.NotNull(body, nameof(body));
var jsonBody = JsonConvert.SerializeObject(body, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); string jsonBody = JsonConvert.SerializeObject(body, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore });
if (encoding != null && !encoding.Equals(Encoding.UTF8)) if (encoding != null && !encoding.Equals(Encoding.UTF8))
{ {

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using JetBrains.Annotations; using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
using SimMetrics.Net; using SimMetrics.Net;
@@ -292,14 +293,26 @@ namespace WireMock.Server
Method = logEntry.RequestMessage.Method, Method = logEntry.RequestMessage.Method,
Body = logEntry.RequestMessage.Body, Body = logEntry.RequestMessage.Body,
Headers = logEntry.RequestMessage.Headers, Headers = logEntry.RequestMessage.Headers,
Cookies = logEntry.RequestMessage.Cookies Cookies = logEntry.RequestMessage.Cookies,
BodyEncoding = logEntry.RequestMessage.BodyEncoding != null ? new EncodingModel
{
EncodingName = logEntry.RequestMessage.BodyEncoding.EncodingName,
CodePage = logEntry.RequestMessage.BodyEncoding.CodePage,
WebName = logEntry.RequestMessage.BodyEncoding.WebName
} : null
}, },
Response = new LogResponseModel Response = new LogResponseModel
{ {
StatusCode = logEntry.ResponseMessage.StatusCode, StatusCode = logEntry.ResponseMessage.StatusCode,
Body = logEntry.ResponseMessage.Body, Body = logEntry.ResponseMessage.Body,
BodyOriginal = logEntry.ResponseMessage.BodyOriginal, BodyOriginal = logEntry.ResponseMessage.BodyOriginal,
Headers = logEntry.ResponseMessage.Headers Headers = logEntry.ResponseMessage.Headers,
BodyEncoding = logEntry.ResponseMessage.BodyEncoding != null ? new EncodingModel
{
EncodingName = logEntry.ResponseMessage.BodyEncoding.EncodingName,
CodePage = logEntry.ResponseMessage.BodyEncoding.CodePage,
WebName = logEntry.ResponseMessage.BodyEncoding.WebName
} : null
}, },
MappingGuid = logEntry.MappingGuid, MappingGuid = logEntry.MappingGuid,
RequestMatchResult = logEntry.RequestMatchResult != null ? new LogRequestMatchModel RequestMatchResult = logEntry.RequestMatchResult != null ? new LogRequestMatchModel
@@ -418,11 +431,11 @@ namespace WireMock.Server
responseBuilder = responseBuilder.WithHeaders(responseModel.Headers); responseBuilder = responseBuilder.WithHeaders(responseModel.Headers);
if (responseModel.Body != null) if (responseModel.Body != null)
responseBuilder = responseBuilder.WithBody(responseModel.Body); responseBuilder = responseBuilder.WithBody(responseModel.Body, ToEncoding(responseModel.BodyEncoding));
else if (responseModel.BodyAsJson != null) else if (responseModel.BodyAsJson != null)
responseBuilder = responseBuilder.WithBodyAsJson(responseModel.BodyAsJson); responseBuilder = responseBuilder.WithBodyAsJson(responseModel.BodyAsJson, ToEncoding(responseModel.BodyEncoding));
else if (responseModel.BodyAsBase64 != null) else if (responseModel.BodyAsBase64 != null)
responseBuilder = responseBuilder.WithBodyAsBase64(responseModel.BodyAsBase64); responseBuilder = responseBuilder.WithBodyAsBase64(responseModel.BodyAsBase64, ToEncoding(responseModel.BodyEncoding));
if (responseModel.UseTransformer) if (responseModel.UseTransformer)
responseBuilder = responseBuilder.WithTransformer(); responseBuilder = responseBuilder.WithTransformer();
@@ -500,7 +513,14 @@ namespace WireMock.Server
Headers = response.ResponseMessage.Headers, Headers = response.ResponseMessage.Headers,
Body = response.ResponseMessage.Body, Body = response.ResponseMessage.Body,
UseTransformer = response.UseTransformer, UseTransformer = response.UseTransformer,
Delay = response.Delay?.Milliseconds Delay = response.Delay?.Milliseconds,
BodyEncoding = response.ResponseMessage.BodyEncoding != null ? new EncodingModel
{
EncodingName = response.ResponseMessage.BodyEncoding.EncodingName,
CodePage = response.ResponseMessage.BodyEncoding.CodePage,
WebName = response.ResponseMessage.BodyEncoding.WebName
} : null
} }
}; };
} }
@@ -590,5 +610,10 @@ namespace WireMock.Server
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } } Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
}; };
} }
private Encoding ToEncoding(EncodingModel encodingModel)
{
return encodingModel != null ? Encoding.GetEncoding(encodingModel.CodePage) : null;
}
} }
} }

View File

@@ -22,8 +22,8 @@ namespace WireMock.Net.Tests
public void Should_parse_query_params() public void Should_parse_query_params()
{ {
// given // given
var bodyAsString = "whatever"; string bodyAsString = "whatever";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost?foo=bar&multi=1&multi=2"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost?foo=bar&multi=1&multi=2"), "POST", body, bodyAsString, Encoding.UTF8);
// then // then

View File

@@ -144,8 +144,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingDelete(); var spec = Request.Create().WithPath("/foo").UsingDelete();
// when // when
var bodyAsString = "whatever"; string bodyAsString = "whatever";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "Delete", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "Delete", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -202,8 +202,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata"); var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
// when // when
var bodyAsString = "whatever"; string bodyAsString = "whatever";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary <string, string> { { "X-toto", "tata" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary <string, string> { { "X-toto", "tata" } });
// then // then
@@ -218,8 +218,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tatata"); var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tatata");
// when // when
var bodyAsString = "whatever"; string bodyAsString = "whatever";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary <string, string> { { "X-toto", "tata" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary <string, string> { { "X-toto", "tata" } });
// then // then
@@ -234,8 +234,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "abc", false); var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "abc", false);
// when // when
var bodyAsString = "whatever"; string bodyAsString = "whatever";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary <string, string> { { "X-toto", "ABC" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary <string, string> { { "X-toto", "ABC" } });
// then // then
@@ -250,8 +250,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tata*"); var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tata*");
// when // when
var bodyAsString = "whatever"; string bodyAsString = "whatever";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "X-toto", "TaTa" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "X-toto", "TaTa" } });
// then // then
@@ -280,8 +280,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithBody("Hello world!"); var spec = Request.Create().UsingAnyVerb().WithBody("Hello world!");
// when // when
var bodyAsString = "Hello world!"; string bodyAsString = "Hello world!";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -296,8 +296,8 @@ namespace WireMock.Net.Tests
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
// when // when
var bodyAsString = "cat"; string bodyAsString = "cat";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -312,8 +312,8 @@ namespace WireMock.Net.Tests
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat", "dog")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat", "dog"));
// when // when
var bodyAsString = "cat"; string bodyAsString = "cat";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -328,8 +328,8 @@ namespace WireMock.Net.Tests
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
// when // when
var bodyAsString = "caR"; string bodyAsString = "caR";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -344,8 +344,8 @@ namespace WireMock.Net.Tests
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street.")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street."));
// when // when
var bodyAsString = "The car drives in the street."; string bodyAsString = "The car drives in the street.";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -360,8 +360,8 @@ namespace WireMock.Net.Tests
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street.")); var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street."));
// when // when
var bodyAsString = "Hello"; string bodyAsString = "Hello";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -376,8 +376,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new WildcardMatcher("H*o*")); var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new WildcardMatcher("H*o*"));
// when // when
var bodyAsString = "Hello world!"; string bodyAsString = "Hello world!";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "X-toto", "tatata" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then // then
@@ -392,8 +392,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithBody(new RegexMatcher("H.*o")); var spec = Request.Create().UsingAnyVerb().WithBody(new RegexMatcher("H.*o"));
// when // when
var bodyAsString = "Hello world!"; string bodyAsString = "Hello world!";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -414,7 +414,7 @@ namespace WireMock.Net.Tests
<todo-item id='a2'>def</todo-item> <todo-item id='a2'>def</todo-item>
<todo-item id='a3'>xyz</todo-item> <todo-item id='a3'>xyz</todo-item>
</todo-list>"; </todo-list>";
var body = Encoding.UTF8.GetBytes(xmlBodyAsString); byte[] body = Encoding.UTF8.GetBytes(xmlBodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, xmlBodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, xmlBodyAsString, Encoding.UTF8);
// then // then
@@ -435,7 +435,7 @@ namespace WireMock.Net.Tests
<todo-item id='a2'>def</todo-item> <todo-item id='a2'>def</todo-item>
<todo-item id='a3'>xyz</todo-item> <todo-item id='a3'>xyz</todo-item>
</todo-list>"; </todo-list>";
var body = Encoding.UTF8.GetBytes(xmlBodyAsString); byte[] body = Encoding.UTF8.GetBytes(xmlBodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, xmlBodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, xmlBodyAsString, Encoding.UTF8);
// then // then
@@ -450,8 +450,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")); var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
// when // when
var bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }"; string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -466,8 +466,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")); var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
// when // when
var bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }"; string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8);
// then // then
@@ -482,8 +482,8 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyVerb().WithBody(" Hello world! "); var spec = Request.Create().UsingAnyVerb().WithBody(" Hello world! ");
// when // when
var bodyAsString = "xxx"; string bodyAsString = "xxx";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "X-toto", "tatata" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then // then

View File

@@ -15,8 +15,8 @@ namespace WireMock.Net.Tests
public async Task Response_ProvideResponse_Handlebars_UrlPathVerb() public async Task Response_ProvideResponse_Handlebars_UrlPathVerb()
{ {
// given // given
var bodyAsString = "abc"; string bodyAsString = "abc";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
var response = Response.Create() var response = Response.Create()
@@ -34,8 +34,8 @@ namespace WireMock.Net.Tests
public async Task Response_ProvideResponse_Handlebars_Query() public async Task Response_ProvideResponse_Handlebars_Query()
{ {
// given // given
var bodyAsString = "abc"; string bodyAsString = "abc";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", body, bodyAsString, Encoding.UTF8);
var response = Response.Create() var response = Response.Create()
@@ -53,8 +53,8 @@ namespace WireMock.Net.Tests
public async Task Response_ProvideResponse_Handlebars_Headers() public async Task Response_ProvideResponse_Handlebars_Headers()
{ {
// given // given
var bodyAsString = "abc"; string bodyAsString = "abc";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "Content-Type", "text/plain" } }); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8, new Dictionary<string, string> { { "Content-Type", "text/plain" } });
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}").WithBody("test").WithTransformer(); var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}").WithBody("test").WithTransformer();
@@ -71,8 +71,8 @@ namespace WireMock.Net.Tests
public async Task Response_ProvideResponse_Encoding_Body() public async Task Response_ProvideResponse_Encoding_Body()
{ {
// given // given
var bodyAsString = "abc"; string bodyAsString = "abc";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
var response = Response.Create().WithBody("test", Encoding.ASCII); var response = Response.Create().WithBody("test", Encoding.ASCII);
@@ -89,8 +89,8 @@ namespace WireMock.Net.Tests
public async Task Response_ProvideResponse_Encoding_JsonBody() public async Task Response_ProvideResponse_Encoding_JsonBody()
{ {
// given // given
var bodyAsString = "abc"; string bodyAsString = "abc";
var body = Encoding.UTF8.GetBytes(bodyAsString); byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8); var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, Encoding.UTF8);
var response = Response.Create().WithBodyAsJson(new { value = "test" }, Encoding.ASCII); var response = Response.Create().WithBodyAsJson(new { value = "test" }, Encoding.ASCII);