This commit is contained in:
Stef Heyenrath
2021-03-18 14:29:13 +01:00
committed by GitHub
parent 3617e95db6
commit ddf2b49240
5 changed files with 133 additions and 66 deletions

View File

@@ -2,6 +2,7 @@ using JetBrains.Annotations;
using System;
using System.Linq;
using WireMock.Types;
using WireMock.Util;
using WireMock.Validation;
namespace WireMock.Matchers.Request
@@ -26,6 +27,11 @@ namespace WireMock.Matchers.Request
/// </summary>
public Func<object, bool> JsonFunc { get; }
/// <summary>
/// The body data function for BodyData
/// </summary>
public Func<IBodyData, bool> BodyDataFunc { get; }
/// <summary>
/// The matchers.
/// </summary>
@@ -88,6 +94,16 @@ namespace WireMock.Matchers.Request
JsonFunc = func;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="func">The function.</param>
public RequestMessageBodyMatcher([NotNull] Func<IBodyData, bool> func)
{
Check.NotNull(func, nameof(func));
BodyDataFunc = func;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
@@ -158,6 +174,11 @@ namespace WireMock.Matchers.Request
return MatchScores.ToScore(DataFunc(requestMessage?.BodyData?.BodyAsBytes));
}
if (BodyDataFunc != null)
{
return MatchScores.ToScore(BodyDataFunc(requestMessage?.BodyData));
}
return MatchScores.Mismatch;
}
}