mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
* Update examples (#158) * IIS debug * PathBase logic * 1.0.4.5-preview-01 * Fix project and readme * Fix issues * fix picture alignment * Add IIS publish examples * 1.0.4.5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
using Xunit;
|
||||
|
||||
@@ -15,7 +16,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
// Assign
|
||||
var responseMessage = new ResponseMessage { StatusCode = 500 };
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
|
||||
var response = Response.Create(() => responseMessage);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
@@ -20,7 +21,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.String, Encoding.ASCII);
|
||||
|
||||
@@ -41,7 +42,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.SameAsSource, Encoding.ASCII);
|
||||
|
||||
@@ -62,7 +63,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create().WithBody("test", null, Encoding.ASCII);
|
||||
|
||||
@@ -82,7 +83,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
object x = new { value = "test" };
|
||||
var response = Response.Create().WithBodyAsJson(x, Encoding.ASCII);
|
||||
@@ -100,7 +101,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_String_SameAsSource_Encoding()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
|
||||
var response = Response.Create().WithBody("r", BodyDestinationFormat.SameAsSource, Encoding.ASCII);
|
||||
|
||||
@@ -118,7 +119,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_String_Bytes_Encoding()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
|
||||
var response = Response.Create().WithBody("r", BodyDestinationFormat.Bytes, Encoding.ASCII);
|
||||
|
||||
@@ -136,7 +137,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithBody_String_Json_Encoding()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
|
||||
var response = Response.Create().WithBody("{ \"value\": 42 }", BodyDestinationFormat.Json, Encoding.ASCII);
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Owin;
|
||||
using Newtonsoft.Json;
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
public class ResponseWithBodyHandlebarsTests
|
||||
public class ResponseWithHandlebarsTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
@@ -24,7 +26,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
|
||||
Encoding = Encoding.UTF8
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, bodyData);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBodyAsJson(new { x = "test {{request.url}}" })
|
||||
@@ -45,7 +47,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "whatever"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("test {{request.url}} {{request.path}} {{request.method}}")
|
||||
@@ -58,6 +60,42 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
Check.That(responseMessage.Body).Equals("test http://localhost/foo /foo post");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_Handlebars_UrlPath()
|
||||
{
|
||||
// given
|
||||
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
|
||||
var request = new RequestMessage(urlDetails, "POST", ClientIp);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("{{request.url}} {{request.absoluteurl}} {{request.path}} {{request.absolutepath}}")
|
||||
.WithTransformer();
|
||||
|
||||
// act
|
||||
var responseMessage = await response.ProvideResponseAsync(request);
|
||||
|
||||
// then
|
||||
Check.That(responseMessage.Body).Equals("http://localhost/a/b http://localhost/wiremock/a/b /a/b /wiremock/a/b");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_Handlebars_PathSegments()
|
||||
{
|
||||
// given
|
||||
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
|
||||
var request = new RequestMessage(urlDetails, "POST", ClientIp);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("{{request.pathsegments.[0]}} {{request.absolutepathsegments.[0]}}")
|
||||
.WithTransformer();
|
||||
|
||||
// act
|
||||
var responseMessage = await response.ProvideResponseAsync(request);
|
||||
|
||||
// then
|
||||
Check.That(responseMessage.Body).Equals("a wiremock");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_Handlebars_Query()
|
||||
{
|
||||
@@ -66,7 +104,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("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}}")
|
||||
@@ -87,7 +125,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
|
||||
var request = new RequestMessage(new UrlDetails("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();
|
||||
|
||||
@@ -108,7 +146,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
|
||||
var request = new RequestMessage(new UrlDetails("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();
|
||||
|
||||
@@ -130,7 +168,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
{
|
||||
BodyAsString = "abc"
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost:1234"), "POST", ClientIp, body);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "POST", ClientIp, body);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBody("test {{request.origin}} {{request.port}} {{request.protocol}} {{request.host}}")
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithHeaders_SingleValue()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
var headers = new Dictionary<string, string> { { "h", "x" } };
|
||||
var response = Response.Create().WithHeaders(headers);
|
||||
|
||||
@@ -31,7 +32,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithHeaders_MultipleValues()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
|
||||
var response = Response.Create().WithHeaders(headers);
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
public async Task Response_ProvideResponse_WithHeaders_WiremockList()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
|
||||
var headers = new Dictionary<string, WireMockList<string>> { { "h", new WireMockList<string>("x") } };
|
||||
var response = Response.Create().WithHeaders(headers);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user