mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-19 16:21:49 +01:00
Add some more tests
This commit is contained in:
13
src/WireMock.Net/Matchers/IIgnoreCaseMatcher.cs
Normal file
13
src/WireMock.Net/Matchers/IIgnoreCaseMatcher.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
/// <summary>
|
||||
/// IIgnoreCaseMatcher
|
||||
/// </summary>
|
||||
public interface IIgnoreCaseMatcher : IMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// Ignore the case.
|
||||
/// </summary>
|
||||
bool IgnoreCase { get; }
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace WireMock.Matchers
|
||||
/// Regular Expression Matcher
|
||||
/// </summary>
|
||||
/// <seealso cref="IStringMatcher" />
|
||||
public class RegexMatcher : IStringMatcher
|
||||
public class RegexMatcher : IStringMatcher, IIgnoreCaseMatcher
|
||||
{
|
||||
private readonly string[] _patterns;
|
||||
private readonly Regex[] _expressions;
|
||||
@@ -34,6 +34,7 @@ namespace WireMock.Matchers
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
|
||||
_patterns = patterns;
|
||||
IgnoreCase = ignoreCase;
|
||||
|
||||
RegexOptions options = RegexOptions.Compiled;
|
||||
if (ignoreCase)
|
||||
@@ -73,5 +74,8 @@ namespace WireMock.Matchers
|
||||
{
|
||||
return "RegexMatcher";
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
||||
public bool IgnoreCase { get; }
|
||||
}
|
||||
}
|
||||
@@ -104,15 +104,13 @@ namespace WireMock.Matchers.Request
|
||||
{
|
||||
if (requestMessage.Body != null)
|
||||
{
|
||||
var stringMatcher = Matcher as IStringMatcher;
|
||||
if (stringMatcher != null)
|
||||
if (Matcher is IStringMatcher stringMatcher)
|
||||
{
|
||||
return stringMatcher.IsMatch(requestMessage.Body);
|
||||
}
|
||||
}
|
||||
|
||||
var objectMatcher = Matcher as IObjectMatcher;
|
||||
if (objectMatcher != null)
|
||||
if (Matcher is IObjectMatcher objectMatcher)
|
||||
{
|
||||
if (requestMessage.BodyAsJson != null)
|
||||
{
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace WireMock.Serialization
|
||||
return newDictionary;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static string[] Map<T>([CanBeNull] IEnumerable<Func<T, bool>> funcs)
|
||||
{
|
||||
|
||||
@@ -20,15 +20,16 @@ namespace WireMock.Serialization
|
||||
return null;
|
||||
}
|
||||
|
||||
IStringMatcher stringMatcher = matcher as IStringMatcher;
|
||||
string[] patterns = stringMatcher != null ? stringMatcher.GetPatterns() : new string[0];
|
||||
string[] patterns = matcher is IStringMatcher stringMatcher ? stringMatcher.GetPatterns() : new string[0];
|
||||
bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)null;
|
||||
|
||||
return new MatcherModel
|
||||
{
|
||||
IgnoreCase = ignorecase,
|
||||
Name = matcher.GetName(),
|
||||
Pattern = patterns.Length == 1 ? patterns.First() : null,
|
||||
Patterns = patterns.Length > 1 ? patterns : null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user