mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-22 16:58:58 +02:00
ct
This commit is contained in:
@@ -10,6 +10,8 @@ namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class FormUrlEncodedMatcherTest
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
[Theory]
|
||||
[InlineData("*=*")]
|
||||
[InlineData("name=John Doe")]
|
||||
@@ -25,12 +27,12 @@ public class FormUrlEncodedMatcherTest
|
||||
public async Task FormUrlEncodedMatcher_IsMatch(params string[] patterns)
|
||||
{
|
||||
// Arrange
|
||||
var content = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
var content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string, string>("name", "John Doe"),
|
||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||
});
|
||||
var contentAsString = await content.ReadAsStringAsync();
|
||||
]);
|
||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||
|
||||
var matcher = new FormUrlEncodedMatcher(patterns.Select(p => new AnyOf<string, StringPattern>(p)).ToArray());
|
||||
|
||||
@@ -56,12 +58,12 @@ public class FormUrlEncodedMatcherTest
|
||||
public async Task FormUrlEncodedMatcher_IsMatch_And(bool expected, params string[] patterns)
|
||||
{
|
||||
// Arrange
|
||||
var content = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
var content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string, string>("name", "John Doe"),
|
||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||
});
|
||||
var contentAsString = await content.ReadAsStringAsync();
|
||||
]);
|
||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||
|
||||
var matcher = new FormUrlEncodedMatcher(patterns.Select(p => new AnyOf<string, StringPattern>(p)).ToArray(), true, MatchOperator.And);
|
||||
|
||||
@@ -76,12 +78,12 @@ public class FormUrlEncodedMatcherTest
|
||||
public async Task FormUrlEncodedMatcher_IsMatch_And_MatchAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
var content = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
var content = new FormUrlEncodedContent(
|
||||
[
|
||||
new KeyValuePair<string, string>("name", "John Doe"),
|
||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||
});
|
||||
var contentAsString = await content.ReadAsStringAsync();
|
||||
]);
|
||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||
|
||||
// The expectation is that the matcher requires all properties to be present in the content.
|
||||
var matcher = new FormUrlEncodedMatcher(["name=*", "email=*", "required=*"], matchOperator: MatchOperator.And);
|
||||
|
||||
@@ -414,7 +414,7 @@ public class JsonPartialMatcherTests
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string? input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialMatcher(value);
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class ProtoBufMatcherTests
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
private const string MessageType = "greet.HelloRequest";
|
||||
|
||||
private static IdOrTexts ProtoDefinition => new(null, @"
|
||||
@@ -37,7 +39,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType);
|
||||
var result = await matcher.DecodeAsync(bytes);
|
||||
var result = await matcher.DecodeAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Should().BeEquivalentTo(new { name = "stef" });
|
||||
@@ -51,7 +53,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType);
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Perfect);
|
||||
@@ -67,7 +69,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType, matcher: jsonMatcher);
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Perfect);
|
||||
@@ -82,7 +84,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, MessageType);
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Mismatch);
|
||||
@@ -97,7 +99,7 @@ message HelloReply {
|
||||
|
||||
// Act
|
||||
var matcher = new ProtoBufMatcher(() => ProtoDefinition, "greet.Greeter.X");
|
||||
var result = await matcher.IsMatchAsync(bytes);
|
||||
var result = await matcher.IsMatchAsync(bytes, _ct);
|
||||
|
||||
// Assert
|
||||
result.Score.Should().Be(MatchScores.Mismatch);
|
||||
|
||||
Reference in New Issue
Block a user