mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 18:59:02 +02:00
Add Func<> matchhing. Solves issue #2
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using JetBrains.Annotations;
|
||||
using System.Text.RegularExpressions;
|
||||
using WireMock.Validation;
|
||||
@@ -29,6 +30,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
private readonly Regex urlRegex;
|
||||
|
||||
/// <summary>
|
||||
/// The url function
|
||||
/// </summary>
|
||||
private readonly Func<string, bool> urlFunc;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
|
||||
/// </summary>
|
||||
@@ -41,6 +47,18 @@ namespace WireMock
|
||||
urlRegex = new Regex(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
|
||||
/// </summary>
|
||||
/// <param name="func">
|
||||
/// The url func.
|
||||
/// </param>
|
||||
public RequestUrlSpec(Func<string, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
urlFunc = func;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The is satisfied by.
|
||||
/// </summary>
|
||||
@@ -52,7 +70,7 @@ namespace WireMock
|
||||
/// </returns>
|
||||
public bool IsSatisfiedBy(RequestMessage requestMessage)
|
||||
{
|
||||
return urlRegex.IsMatch(requestMessage.Url);
|
||||
return urlRegex?.IsMatch(requestMessage.Url) ?? urlFunc(requestMessage.Url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user