mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 01:50:36 +01:00
...
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="WireMock.Net" Version="1.8.11" />
|
||||
<PackageReference Include="WireMock.Net" Version="1.23.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -27,7 +27,7 @@ public partial class WireMockServerTests
|
||||
var textPlainMatcher = new MimePartMatcher(MatchBehaviour.AcceptOnMatch, textPlainContentTypeMatcher, null, null, textPlainContentMatcher);
|
||||
|
||||
var textJson = "{ \"Key\" : \"Value\" }";
|
||||
var textJsonContentType = "text/json";
|
||||
var textJsonContentType = "applicatiom/json";
|
||||
var textJsonContentTypeMatcher = new ContentTypeMatcher(textJsonContentType);
|
||||
var textJsonContentMatcher = new JsonMatcher(new { Key = "Value" }, true);
|
||||
var jsonMatcher = new MimePartMatcher(MatchBehaviour.AcceptOnMatch, textJsonContentTypeMatcher, null, null, textJsonContentMatcher);
|
||||
|
||||
@@ -15,12 +15,12 @@ public class RequestMatchResultTests
|
||||
{
|
||||
// Arrange
|
||||
var result1 = new RequestMatchResult();
|
||||
result1.AddScore(typeof(WildcardMatcher), 1, null);
|
||||
result1.AddScore(typeof(WildcardMatcher), 0.9, null);
|
||||
result1.AddMatchResult(typeof(WildcardMatcher), 1, null);
|
||||
result1.AddMatchResult(typeof(WildcardMatcher), 0.9, null);
|
||||
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddMatchResult(typeof(JsonMatcher), 1, null);
|
||||
result2.AddMatchResult(typeof(JsonMatcher), 1, null);
|
||||
|
||||
var results = new[] { result1, result2 };
|
||||
|
||||
@@ -36,13 +36,13 @@ public class RequestMatchResultTests
|
||||
{
|
||||
// Arrange
|
||||
var result1 = new RequestMatchResult();
|
||||
result1.AddScore(typeof(WildcardMatcher), 1, null);
|
||||
result1.AddScore(typeof(WildcardMatcher), 1, null);
|
||||
result1.AddMatchResult(typeof(WildcardMatcher), 1, null);
|
||||
result1.AddMatchResult(typeof(WildcardMatcher), 1, null);
|
||||
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddMatchResult(typeof(JsonMatcher), 1, null);
|
||||
result2.AddMatchResult(typeof(JsonMatcher), 1, null);
|
||||
result2.AddMatchResult(typeof(JsonMatcher), 1, null);
|
||||
|
||||
var results = new[] { result1, result2 };
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ public class MappingMatcherTests
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
foreach (var score in match.scores)
|
||||
{
|
||||
requestMatchResult.AddScore(typeof(object), score, null);
|
||||
requestMatchResult.AddMatchResult(typeof(object), score, null);
|
||||
}
|
||||
|
||||
mappingMock.SetupGet(m => m.Probability).Returns(match.probability);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock = new Mock<IStringMatcher>();
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(1d);
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), 1d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
@@ -61,10 +61,10 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock1 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(one);
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), one));
|
||||
|
||||
var stringMatcherMock2 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(two);
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), two));
|
||||
|
||||
var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
|
||||
|
||||
@@ -102,10 +102,10 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock1 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(one);
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), one));
|
||||
|
||||
var stringMatcherMock2 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(two);
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), two));
|
||||
|
||||
var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
|
||||
|
||||
@@ -143,10 +143,10 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock1 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(one);
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), one));
|
||||
|
||||
var stringMatcherMock2 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(two);
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), two));
|
||||
|
||||
var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
|
||||
|
||||
@@ -175,11 +175,11 @@ public class RequestMessageBodyMatcherTests
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsBytes = new byte[] { 1 },
|
||||
BodyAsBytes = [1],
|
||||
DetectedBodyType = BodyType.Bytes
|
||||
};
|
||||
var stringMatcherMock = new Mock<IStringMatcher>();
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), 0.5d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
@@ -207,7 +207,7 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var stringMatcherMock = new Mock<IStringMatcher>();
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(1.0d);
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), 1.0d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
@@ -235,7 +235,7 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var stringMatcherMock = new Mock<IStringMatcher>();
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(1d);
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), 1d));
|
||||
stringMatcherMock.SetupGet(m => m.MatchOperator).Returns(MatchOperator.Or);
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
@@ -263,7 +263,7 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.Json
|
||||
};
|
||||
var objectMatcherMock = new Mock<IObjectMatcher>();
|
||||
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(1d);
|
||||
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(MatchResult.From(nameof(IStringMatcher), 1d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
@@ -387,7 +387,7 @@ public class RequestMessageBodyMatcherTests
|
||||
DetectedBodyType = BodyType.Bytes
|
||||
};
|
||||
var objectMatcherMock = new Mock<IObjectMatcher>();
|
||||
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(1.0d);
|
||||
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(MatchResult.From(nameof(IStringMatcher), 1.0d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class RequestMessageGraphQLMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock = new Mock<IStringMatcher>();
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(1d);
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), 1d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
@@ -57,10 +57,10 @@ public class RequestMessageGraphQLMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock1 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(one);
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), one));
|
||||
|
||||
var stringMatcherMock2 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(two);
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), two));
|
||||
|
||||
var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
|
||||
|
||||
@@ -98,10 +98,10 @@ public class RequestMessageGraphQLMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock1 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(one);
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), one));
|
||||
|
||||
var stringMatcherMock2 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(two);
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), two));
|
||||
|
||||
var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
|
||||
|
||||
@@ -139,10 +139,10 @@ public class RequestMessageGraphQLMatcherTests
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var stringMatcherMock1 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(one);
|
||||
stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), one));
|
||||
|
||||
var stringMatcherMock2 = new Mock<IStringMatcher>();
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(two);
|
||||
stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), two));
|
||||
|
||||
var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
|
||||
|
||||
@@ -175,7 +175,7 @@ public class RequestMessageGraphQLMatcherTests
|
||||
DetectedBodyType = BodyType.Bytes
|
||||
};
|
||||
var stringMatcherMock = new Mock<IStringMatcher>();
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
|
||||
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(MatchResult.From(nameof(IStringMatcher), 0.5d));
|
||||
|
||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CustomPathParamMatcher : IStringMatcher
|
||||
var inputParts = GetPathParts(input);
|
||||
if (inputParts.Length != _pathParts.Length)
|
||||
{
|
||||
return MatchScores.Mismatch;
|
||||
return MatchResult.From(Name);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -60,29 +60,29 @@ public class CustomPathParamMatcher : IStringMatcher
|
||||
var pathParamName = pathPart.Trim('{').Trim('}');
|
||||
if (!_pathParams.ContainsKey(pathParamName))
|
||||
{
|
||||
return MatchScores.Mismatch;
|
||||
return MatchResult.From(Name);
|
||||
}
|
||||
|
||||
if (!Regex.IsMatch(inputPart, _pathParams[pathParamName], RegexOptions.IgnoreCase))
|
||||
{
|
||||
return MatchScores.Mismatch;
|
||||
return MatchResult.From(Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!inputPart.Equals(pathPart, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return MatchScores.Mismatch;
|
||||
return MatchResult.From(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return MatchScores.Mismatch;
|
||||
return MatchResult.From(Name);
|
||||
}
|
||||
|
||||
return MatchScores.Perfect;
|
||||
return MatchResult.From(Name, MatchScores.Perfect);
|
||||
}
|
||||
|
||||
public AnyOf<string, StringPattern>[] GetPatterns()
|
||||
|
||||
Reference in New Issue
Block a user