mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 09:18:27 +02:00
Add more tests for JmesPathMatchers and StringUtils.ParseMatchOperator (#1009)
* Add more tests for JmesPathMatchers and StringUtils.ParseMatchOperator * . * prio
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#if !NET452
|
||||
//using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
//using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
@@ -21,6 +20,103 @@ public partial class WireMockServerTests
|
||||
public string? Hi { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithBodyAsJson_Using_PostAsJsonAsync_And_MultipleJmesPathMatchers_ShouldMatch()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.Start();
|
||||
server.Given(
|
||||
Request.Create()
|
||||
.WithPath("/a")
|
||||
.WithBody(
|
||||
new IMatcher[]
|
||||
{
|
||||
new JmesPathMatcher("requestId == '1'"),
|
||||
new JmesPathMatcher("value == 'A'")
|
||||
},
|
||||
MatchOperator.And
|
||||
)
|
||||
.UsingPost()
|
||||
)
|
||||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
|
||||
|
||||
server.Given(
|
||||
Request.Create()
|
||||
.WithPath("/a")
|
||||
.WithBody(
|
||||
new IMatcher[]
|
||||
{
|
||||
new JmesPathMatcher("requestId == '2'"),
|
||||
new JmesPathMatcher("value == 'A'")
|
||||
},
|
||||
MatchOperator.And
|
||||
)
|
||||
.UsingPost()
|
||||
)
|
||||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Moved));
|
||||
|
||||
// Act
|
||||
var requestUri = new Uri($"http://localhost:{server.Port}/a");
|
||||
|
||||
var json = new { requestId = "1", value = "A" };
|
||||
var response = await server.CreateClient().PostAsJsonAsync(requestUri, json).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithBodyAsJson_Using_PostAsJsonAsync_And_MultipleJmesPathMatchers_ShouldMatch_BestMatching()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.Start();
|
||||
server.Given(
|
||||
Request.Create()
|
||||
.WithPath("/a")
|
||||
.WithBody(
|
||||
new IMatcher[]
|
||||
{
|
||||
new JmesPathMatcher("extra == 'X'"),
|
||||
new JmesPathMatcher("requestId == '1'"),
|
||||
new JmesPathMatcher("value == 'A'")
|
||||
},
|
||||
MatchOperator.And
|
||||
)
|
||||
.UsingPost()
|
||||
)
|
||||
.AtPriority(1) // Higher priority
|
||||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
|
||||
|
||||
server.Given(
|
||||
Request.Create()
|
||||
.WithPath("/a")
|
||||
.WithBody(
|
||||
new IMatcher[]
|
||||
{
|
||||
new JmesPathMatcher("requestId == '1'"),
|
||||
new JmesPathMatcher("value == 'A'")
|
||||
},
|
||||
MatchOperator.And
|
||||
)
|
||||
.UsingPost()
|
||||
)
|
||||
.AtPriority(2)
|
||||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Moved));
|
||||
|
||||
// Act
|
||||
var requestUri = new Uri($"http://localhost:{server.Port}/a");
|
||||
|
||||
var json = new { extra = "X", requestId = "1", value = "A" };
|
||||
var response = await server.CreateClient().PostAsJsonAsync(requestUri, json).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithBodyAsJson_Using_PostAsJsonAsync_And_WildcardMatcher_ShouldMatch()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user