mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-27 19:27:42 +02:00
MatcherMapper : Always use Pattern (#716)
This commit is contained in:
@@ -1,22 +1,33 @@
|
|||||||
{
|
{
|
||||||
"Request": {
|
"Request": {
|
||||||
"Path": {
|
"Path": {
|
||||||
"Matchers": [
|
"Matchers": [
|
||||||
{
|
{
|
||||||
"Name": "WildcardMatcher",
|
"Name": "WildcardMatcher",
|
||||||
"Pattern": "/static/mapping"
|
"Patterns": [ "/static/mapping", "/static/mapping2" ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"Body": {
|
||||||
|
"Matcher": {
|
||||||
|
"Name": "JsonMatcher",
|
||||||
|
"Pattern": {
|
||||||
|
"post1": "value 1",
|
||||||
|
"post2": "value 2"
|
||||||
|
},
|
||||||
|
"IgnoreCase": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"Methods": [
|
"Methods": [
|
||||||
"get"
|
"get",
|
||||||
|
"post"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Response": {
|
"Response": {
|
||||||
"BodyAsJson": { "body": "static mapping" },
|
"BodyAsJson": { "body": "static mapping" },
|
||||||
"Headers": {
|
"Headers": {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Test-X": [ "test 1", "test 2" ]
|
"Test-X": [ "test 1", "test 2" ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using System;
|
using System;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
|
|||||||
@@ -161,12 +161,12 @@ namespace WireMock.Serialization
|
|||||||
|
|
||||||
// If the matcher is a IValueMatcher, get the value (can be string or object).
|
// If the matcher is a IValueMatcher, get the value (can be string or object).
|
||||||
case IValueMatcher valueMatcher:
|
case IValueMatcher valueMatcher:
|
||||||
model.Patterns = new[] { valueMatcher.Value };
|
model.Pattern = valueMatcher.Value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// If the matcher is a ExactObjectMatcher, get the ValueAsObject or ValueAsBytes.
|
// If the matcher is a ExactObjectMatcher, get the ValueAsObject or ValueAsBytes.
|
||||||
case ExactObjectMatcher exactObjectMatcher:
|
case ExactObjectMatcher exactObjectMatcher:
|
||||||
model.Patterns = new[] { exactObjectMatcher.ValueAsObject ?? exactObjectMatcher.ValueAsBytes };
|
model.Pattern = exactObjectMatcher.ValueAsObject ?? exactObjectMatcher.ValueAsBytes;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithTimeSetrtings_ReturnsCorrectTimeSettings()
|
public void ToMappingModel_WithTimeSettings_ReturnsCorrectTimeSettings()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var start = DateTime.Now;
|
var start = DateTime.Now;
|
||||||
|
|||||||
@@ -187,16 +187,36 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_As_String()
|
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_1_Value_As_String()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var pattern = "{ \"post1\": \"value1\", \"post2\": \"value2\" }";
|
||||||
|
var patterns = new[] { pattern };
|
||||||
|
var model = new MatcherModel
|
||||||
|
{
|
||||||
|
Name = "JsonMatcher",
|
||||||
|
Patterns = patterns
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = (JsonMatcher)_sut.Map(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||||
|
matcher.Value.Should().BeEquivalentTo(patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_2_Values_As_String()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var pattern1 = "{ \"AccountIds\": [ 1, 2, 3 ] }";
|
var pattern1 = "{ \"AccountIds\": [ 1, 2, 3 ] }";
|
||||||
var pattern2 = "{ \"X\": \"x\" }";
|
var pattern2 = "{ \"post1\": \"value1\", \"post2\": \"value2\" }";
|
||||||
var patterns = new[] { pattern1, pattern2 };
|
var patterns = new[] { pattern1, pattern2 };
|
||||||
var model = new MatcherModel
|
var model = new MatcherModel
|
||||||
{
|
{
|
||||||
Name = "JsonMatcher",
|
Name = "JsonMatcher",
|
||||||
Pattern = patterns
|
Patterns = patterns
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -227,11 +247,31 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_As_Object()
|
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_1_Value_As_Object()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
object pattern = new { post1 = "value1", post2 = "value2" };
|
||||||
|
var patterns = new[] { pattern };
|
||||||
|
var model = new MatcherModel
|
||||||
|
{
|
||||||
|
Name = "JsonMatcher",
|
||||||
|
Patterns = patterns
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = (JsonMatcher)_sut.Map(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||||
|
matcher.Value.Should().BeEquivalentTo(patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_2_Values_As_Object()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
object pattern1 = new { AccountIds = new[] { 1, 2, 3 } };
|
object pattern1 = new { AccountIds = new[] { 1, 2, 3 } };
|
||||||
object pattern2 = new { X = "x" };
|
object pattern2 = new { post1 = "value1", post2 = "value2" };
|
||||||
var patterns = new[] { pattern1, pattern2 };
|
var patterns = new[] { pattern1, pattern2 };
|
||||||
var model = new MatcherModel
|
var model = new MatcherModel
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user