Issue: JsonPathMatcher - not working for rootless jsons?
Hi, Could you pls help me with defining a JsonPathMatcher for a json of the type:
{
id: 1,
name: "AwesomeName"
}
I have tried "$.[?(@.id == 1)]" but it doesn't seem to work.
I tried it with the following test as well:
// given
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.[?(@.id == 1)]"));
// when
string bodyAsString = "{ \"id\": 1, \"name\": \"AwesomeName\" }";
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
// then
var requestMatchResult = new RequestMatchResult();
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
When testing at http://jsonpath.herokuapp.com/
This works...

So actually, I don't know what's wrong?
I tried it like this:
[Test]
public void Request_WithBodyJsonPathMatcher_true()
{
// given
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.[?(@.Id == 1)]"));
var requestData = new JsonObject()
{
Id = 1,
Name = "AwesomeName"
};
var bodyData = new BodyData {BodyAsJson = requestData};
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", "::1", bodyData);
// then
var requestMatchResult = new RequestMatchResult();
spec.GetMatchingScore(request, requestMatchResult).Should().Be(1);
}
[DataContract]
public sealed class JsonObject
{
[DataMember(Order = 1)]
public int Id { get; set; }
[DataMember(Order = 2)]
public string Name { get; set; }
}
But still no luck. Also tried it against a real mapping with a real request using Postman & JaSon and only got the "No matching found" response.
For some reason:
It should be "$..[?(@.Id == 1)]".
See linked unit-test.---> https://github.com/WireMock-Net/WireMock.Net/commit/2b8a58c68ce53e94070e61f08e28ca0a354f3686
Maybe a bit related to https://github.com/JamesNK/Newtonsoft.Json/issues/1256 ?
@FSatmar This is now fixed, please check new NuGet 1.0.3.12
Great, it's working with the double dots, thank you very much!