Add Func<> matchhing. Solves issue #2

This commit is contained in:
Stef Heyenrath
2017-01-18 20:45:38 +01:00
parent 9d1fd8fd51
commit 65c17ff519
16 changed files with 321 additions and 118 deletions

View File

@@ -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);
}
}
}
}