diff --git a/Directory.Build.props b/Directory.Build.props
index cb15dbda..afa561dd 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -45,7 +45,7 @@
-
+
diff --git a/src/WireMock.Net.Aspire/WireMock.Net.Aspire.csproj b/src/WireMock.Net.Aspire/WireMock.Net.Aspire.csproj
index 70178031..cc4337cb 100644
--- a/src/WireMock.Net.Aspire/WireMock.Net.Aspire.csproj
+++ b/src/WireMock.Net.Aspire/WireMock.Net.Aspire.csproj
@@ -37,7 +37,6 @@
-
diff --git a/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs b/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs
index decbb1d8..d1208867 100644
--- a/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs
+++ b/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs
@@ -1,6 +1,7 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
+using System.Linq;
using AnyOfTypes;
using Stef.Validation;
using WireMock.Models;
@@ -27,7 +28,7 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
///
/// The pattern.
/// Ignore the case from the pattern.
- /// The to use. (default = "Or")
+ /// The to use. (default = "Or")
public FormUrlEncodedMatcher(
AnyOf pattern,
bool ignoreCase = false,
@@ -42,7 +43,7 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
/// The match behaviour.
/// The pattern.
/// Ignore the case from the pattern.
- /// The to use. (default = "Or")
+ /// The to use. (default = "Or")
public FormUrlEncodedMatcher(
MatchBehaviour matchBehaviour,
AnyOf pattern,
@@ -57,7 +58,7 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
///
/// The patterns.
/// Ignore the case from the pattern.
- /// The to use. (default = "Or")
+ /// The to use. (default = "Or")
public FormUrlEncodedMatcher(
AnyOf[] patterns,
bool ignoreCase = false,
@@ -72,7 +73,7 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
/// The match behaviour.
/// The patterns.
/// Ignore the case from the pattern.
- /// The to use. (default = "Or")
+ /// The to use. (default = "Or")
public FormUrlEncodedMatcher(
MatchBehaviour matchBehaviour,
AnyOf[] patterns,
@@ -112,7 +113,20 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
return new MatchResult(MatchScores.Mismatch);
}
+ var matches = GetMatches(inputNameValueCollection);
+
+ var score = MatchScores.ToScore(matches, MatchOperator);
+ return new MatchResult(MatchBehaviourHelper.Convert(MatchBehaviour, score));
+ }
+
+ private bool[] GetMatches(IDictionary inputNameValueCollection)
+ {
var matches = new List();
+ if (_pairs.Count > inputNameValueCollection.Count)
+ {
+ matches.AddRange(Enumerable.Repeat(false, _pairs.Count - inputNameValueCollection.Count));
+ }
+
foreach (var inputKeyValuePair in inputNameValueCollection)
{
var match = false;
@@ -132,8 +146,7 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
matches.Add(match);
}
- var score = MatchScores.ToScore(matches.ToArray(), MatchOperator);
- return new MatchResult(MatchBehaviourHelper.Convert(MatchBehaviour, score));
+ return matches.ToArray();
}
///
diff --git a/test/WireMock.Net.Tests/Matchers/FormUrlEncodedMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/FormUrlEncodedMatcherTests.cs
index 712b4ece..4bb6a80d 100644
--- a/test/WireMock.Net.Tests/Matchers/FormUrlEncodedMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/FormUrlEncodedMatcherTests.cs
@@ -75,4 +75,25 @@ public class FormUrlEncodedMatcherTest
// Assert
score.Should().Be(expected);
}
+
+ [Fact]
+ public async Task FormUrlEncodedMatcher_IsMatch_And_MatchAllProperties()
+ {
+ // Arrange
+ var content = new FormUrlEncodedContent(new[]
+ {
+ new KeyValuePair("name", "John Doe"),
+ new KeyValuePair("email", "johndoe@example.com")
+ });
+ var contentAsString = await content.ReadAsStringAsync();
+
+ // 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);
+
+ // Act
+ var score = matcher.IsMatch(contentAsString).IsPerfect();
+
+ // Assert
+ score.Should().BeFalse();
+ }
}
\ No newline at end of file