mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 15:01:18 +02:00
test
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
@@ -34,11 +33,10 @@ public partial class WireMockServerTests
|
|||||||
Request.Create()
|
Request.Create()
|
||||||
.WithPath("/a")
|
.WithPath("/a")
|
||||||
.WithBody(
|
.WithBody(
|
||||||
new IMatcher[]
|
[
|
||||||
{
|
|
||||||
new JmesPathMatcher("requestId == '1'"),
|
new JmesPathMatcher("requestId == '1'"),
|
||||||
new JmesPathMatcher("value == 'A'")
|
new JmesPathMatcher("value == 'A'")
|
||||||
},
|
],
|
||||||
MatchOperator.And
|
MatchOperator.And
|
||||||
)
|
)
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
@@ -49,11 +47,10 @@ public partial class WireMockServerTests
|
|||||||
Request.Create()
|
Request.Create()
|
||||||
.WithPath("/a")
|
.WithPath("/a")
|
||||||
.WithBody(
|
.WithBody(
|
||||||
new IMatcher[]
|
[
|
||||||
{
|
|
||||||
new JmesPathMatcher("requestId == '2'"),
|
new JmesPathMatcher("requestId == '2'"),
|
||||||
new JmesPathMatcher("value == 'A'")
|
new JmesPathMatcher("value == 'A'")
|
||||||
},
|
],
|
||||||
MatchOperator.And
|
MatchOperator.And
|
||||||
)
|
)
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
@@ -81,12 +78,11 @@ public partial class WireMockServerTests
|
|||||||
Request.Create()
|
Request.Create()
|
||||||
.WithPath("/a")
|
.WithPath("/a")
|
||||||
.WithBody(
|
.WithBody(
|
||||||
new IMatcher[]
|
[
|
||||||
{
|
|
||||||
new JmesPathMatcher("extra == 'X'"),
|
new JmesPathMatcher("extra == 'X'"),
|
||||||
new JmesPathMatcher("requestId == '1'"),
|
new JmesPathMatcher("requestId == '1'"),
|
||||||
new JmesPathMatcher("value == 'A'")
|
new JmesPathMatcher("value == 'A'")
|
||||||
},
|
],
|
||||||
MatchOperator.And
|
MatchOperator.And
|
||||||
)
|
)
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
@@ -98,11 +94,10 @@ public partial class WireMockServerTests
|
|||||||
Request.Create()
|
Request.Create()
|
||||||
.WithPath("/a")
|
.WithPath("/a")
|
||||||
.WithBody(
|
.WithBody(
|
||||||
new IMatcher[]
|
[
|
||||||
{
|
|
||||||
new JmesPathMatcher("requestId == '1'"),
|
new JmesPathMatcher("requestId == '1'"),
|
||||||
new JmesPathMatcher("value == 'A'")
|
new JmesPathMatcher("value == 'A'")
|
||||||
},
|
],
|
||||||
MatchOperator.And
|
MatchOperator.And
|
||||||
)
|
)
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
@@ -199,15 +194,47 @@ public partial class WireMockServerTests
|
|||||||
// Assert
|
// Assert
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
|
|
||||||
var responseText = await response.RequestMessage!.Content!.ReadAsStringAsync();
|
var responseText = await response.Content.ReadAsStringAsync();
|
||||||
responseText.Should().Contain("ec475f56d4694b48bc737500ba575b35-1");
|
responseText.Should().Contain("ec475f56d4694b48bc737500ba575b35-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET6_0_OR_GREATER
|
||||||
|
[Fact]
|
||||||
|
public async Task WireMockServer_WithBodyAsJson_Using_PostAsync_And_JsonPartialWildcardMatcher_And_SystemTextJson_ShouldMatch()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using var server = WireMockServer.Start(x => x.DefaultJsonSerializer = new JsonConverter.System.Text.Json.SystemTextJsonConverter() );
|
||||||
|
|
||||||
|
var matcher = new JsonPartialWildcardMatcher(new { id = "^[a-f0-9]{32}-[0-9]$" }, ignoreCase: true, regex: true);
|
||||||
|
server.Given(Request.Create()
|
||||||
|
.WithHeader("Content-Type", "application/json*")
|
||||||
|
.UsingPost()
|
||||||
|
.WithPath("/system-text-json")
|
||||||
|
.WithBody(matcher)
|
||||||
|
)
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithBody("OK")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var content = """{"id":"ec475f56d4694b48bc737500ba575b35-1"}""";
|
||||||
|
var response = await new HttpClient()
|
||||||
|
.PostAsync($"{server.Url}/system-text-json", new StringContent(content, Encoding.UTF8, "application/json"))
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
|
|
||||||
|
var responseText = await response.Content.ReadAsStringAsync();
|
||||||
|
responseText.Should().Contain("OK");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithFunc()
|
public async Task WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithFunc()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var server = WireMockServer.Start();
|
using var server = WireMockServer.Start();
|
||||||
server.Given(
|
server.Given(
|
||||||
Request.Create()
|
Request.Create()
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
@@ -219,7 +246,7 @@ public partial class WireMockServerTests
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("key1", "value1") });
|
var content = new FormUrlEncodedContent([new KeyValuePair<string, string>("key1", "value1")]);
|
||||||
var response = await new HttpClient()
|
var response = await new HttpClient()
|
||||||
.PostAsync($"{server.Url}/foo", content)
|
.PostAsync($"{server.Url}/foo", content)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user