mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-31 14:43:40 +02:00
* Fixes for JsonPath * More tests * Fixes + added tests
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
@@ -198,5 +200,86 @@ namespace WireMock.Net.Tests
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyAsJson_Object_JsonPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string jsonString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||
var bodyData = new BodyData
|
||||
{
|
||||
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
|
||||
Encoding = Encoding.UTF8
|
||||
};
|
||||
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Request_WithBodyAsJson_Array_JsonPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.books[?(@.price < 10)]"));
|
||||
|
||||
// when
|
||||
string jsonString = "{ \"books\": [ { \"category\": \"test1\", \"price\": 8.95 }, { \"category\": \"test2\", \"price\": 20 } ] }";
|
||||
var bodyData = new BodyData
|
||||
{
|
||||
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
|
||||
Encoding = Encoding.UTF8
|
||||
};
|
||||
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyAsObject_ExactObjectMatcher_true()
|
||||
{
|
||||
// Assign
|
||||
object body = DateTime.MinValue;
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(body);
|
||||
|
||||
var bodyData = new BodyData
|
||||
{
|
||||
BodyAsJson = DateTime.MinValue
|
||||
};
|
||||
|
||||
// Act
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyAsBytes_ExactObjectMatcher_true()
|
||||
{
|
||||
// Assign
|
||||
byte[] body = { 123 };
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(body);
|
||||
|
||||
var bodyData = new BodyData
|
||||
{
|
||||
BodyAsBytes = new byte[] { 123 }
|
||||
};
|
||||
|
||||
// Act
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
|
||||
|
||||
// Assert
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user