mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-31 06:33:25 +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:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
@@ -18,6 +20,7 @@ namespace WireMock.Net.Tests
|
||||
public partial class FluentMockServerTests : IDisposable
|
||||
{
|
||||
private FluentMockServer _server;
|
||||
private static string jsonRequestMessage = @"{ ""message"" : ""Hello server"" }";
|
||||
|
||||
// For for AppVeyor + OpenCover
|
||||
private string GetCurrentFolder()
|
||||
@@ -348,6 +351,39 @@ namespace WireMock.Net.Tests
|
||||
Check.That(responseAsBytes).ContainsExactly(new byte[] { 48, 49 });
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ValidMatchersForHelloServerJsonMessage =>
|
||||
new List<object[]>
|
||||
{
|
||||
new object[] { new WildcardMatcher("*Hello server*"), "application/json" },
|
||||
new object[] { new WildcardMatcher("*Hello server*"), "text/plain" },
|
||||
new object[] { new ExactMatcher(jsonRequestMessage), "application/json" },
|
||||
new object[] { new ExactMatcher(jsonRequestMessage), "text/plain" },
|
||||
new object[] { new RegexMatcher("Hello server"), "application/json" },
|
||||
new object[] { new RegexMatcher("Hello server"), "text/plain" },
|
||||
new object[] { new JsonPathMatcher("$..[?(@.message == 'Hello server')]"), "application/json" },
|
||||
new object[] { new JsonPathMatcher("$..[?(@.message == 'Hello server')]"), "text/plain" }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ValidMatchersForHelloServerJsonMessage))]
|
||||
public async Task FluentMockServer_Should_respond_to_valid_matchers_when_sent_json(IMatcher matcher, string contentType)
|
||||
{
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Request.Create().WithPath("/foo").WithBody(matcher))
|
||||
.RespondWith(Response.Create().WithBody("Hello client"));
|
||||
|
||||
// Act
|
||||
var content = new StringContent(jsonRequestMessage, Encoding.UTF8, contentType);
|
||||
var response = await new HttpClient().PostAsync("http://localhost:" + _server.Ports[0] + "/foo", content);
|
||||
|
||||
// Assert
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
Check.That(responseString).Equals("Hello client");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_respond_404_for_unexpected_request()
|
||||
{
|
||||
@@ -569,4 +605,4 @@ namespace WireMock.Net.Tests
|
||||
_serverForProxyForwarding?.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user