mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 23:41:41 +02:00
Added JsonMatcher (#153)
This commit is contained in:
@@ -38,11 +38,11 @@ namespace WireMock.Net.Tests.Matchers
|
||||
public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
|
||||
{
|
||||
// Assign
|
||||
object obj = 1;
|
||||
object obj = new { x = 500, s = "s" };
|
||||
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(obj);
|
||||
double result = matcher.IsMatch(1);
|
||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(1.0);
|
||||
@@ -52,11 +52,11 @@ namespace WireMock.Net.Tests.Matchers
|
||||
public void ExactObjectMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
object obj = 1;
|
||||
object obj = new { x = 500, s = "s" };
|
||||
|
||||
// Act
|
||||
var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
|
||||
double result = matcher.IsMatch(1);
|
||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
|
||||
100
test/WireMock.Net.Tests/Matchers/JsonMatcherTests.cs
Normal file
100
test/WireMock.Net.Tests/Matchers/JsonMatcherTests.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
{
|
||||
public class JsonMatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void JsonMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher("{}");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_GetValue()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher("{}");
|
||||
|
||||
// Act
|
||||
string value = matcher.GetValue();
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string s = null;
|
||||
var matcher = new JsonMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object o = null;
|
||||
var matcher = new JsonMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_JObject_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user