mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 16:58:27 +02:00
func
This commit is contained in:
@@ -21,16 +21,8 @@ public class FuncMatcher : IFuncMatcher
|
||||
/// Initializes a new instance of the <see cref="FuncMatcher"/> class for string matching.
|
||||
/// </summary>
|
||||
/// <param name="func">The function to check if a string is a match.</param>
|
||||
public FuncMatcher(Func<string?, bool> func) : this(MatchBehaviour.AcceptOnMatch, func)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FuncMatcher"/> class for string matching.
|
||||
/// </summary>
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
/// <param name="func">The function to check if a string is a match.</param>
|
||||
public FuncMatcher(MatchBehaviour matchBehaviour, Func<string?, bool> func)
|
||||
public FuncMatcher(Func<string?, bool> func, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
_stringFunc = Guard.NotNull(func);
|
||||
MatchBehaviour = matchBehaviour;
|
||||
@@ -40,16 +32,8 @@ public class FuncMatcher : IFuncMatcher
|
||||
/// Initializes a new instance of the <see cref="FuncMatcher"/> class for byte array matching.
|
||||
/// </summary>
|
||||
/// <param name="func">The function to check if a byte[] is a match.</param>
|
||||
public FuncMatcher(Func<byte[]?, bool> func) : this(MatchBehaviour.AcceptOnMatch, func)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FuncMatcher"/> class for byte array matching.
|
||||
/// </summary>
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
/// <param name="func">The function to check if a byte[] is a match.</param>
|
||||
public FuncMatcher(MatchBehaviour matchBehaviour, Func<byte[]?, bool> func)
|
||||
public FuncMatcher(Func<byte[]?, bool> func, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
_bytesFunc = Guard.NotNull(func);
|
||||
MatchBehaviour = matchBehaviour;
|
||||
@@ -62,7 +46,7 @@ public class FuncMatcher : IFuncMatcher
|
||||
{
|
||||
try
|
||||
{
|
||||
return CreateMatchResult(_stringFunc(stringValue));
|
||||
return MatchResult.From(Name, MatchBehaviour, _stringFunc(stringValue));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -74,7 +58,7 @@ public class FuncMatcher : IFuncMatcher
|
||||
{
|
||||
try
|
||||
{
|
||||
return CreateMatchResult(_bytesFunc(bytesValue));
|
||||
return MatchResult.From(Name, MatchBehaviour, _bytesFunc(bytesValue));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -85,11 +69,6 @@ public class FuncMatcher : IFuncMatcher
|
||||
return MatchResult.From(Name, MatchScores.Mismatch);
|
||||
}
|
||||
|
||||
private MatchResult CreateMatchResult(bool isMatch)
|
||||
{
|
||||
return MatchResult.From(Name, MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(isMatch)));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name => nameof(FuncMatcher);
|
||||
|
||||
@@ -99,8 +78,8 @@ public class FuncMatcher : IFuncMatcher
|
||||
var funcType = _stringFunc != null ? "Func<string?, bool>" : "Func<byte[]?, bool>";
|
||||
return $"new {Name}" +
|
||||
$"(" +
|
||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||
$"/* {funcType} function */" +
|
||||
$"/* {funcType} function */, " +
|
||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}" +
|
||||
$")";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user