Add MatchOperator "Or", "And" and "Average" for patterns (#755)

* wip

* ...

* .

* ...

* ...

* path

* url

* b

* t

* client

* .

* RequestMessageMethodMatcherTests

* .

* h

* .

* fix tests

* .
This commit is contained in:
Stef Heyenrath
2022-06-09 21:31:54 +02:00
committed by GitHub
parent 1f23022460
commit 0441c1d85e
95 changed files with 5736 additions and 5111 deletions

View File

@@ -87,7 +87,7 @@ internal static class JsonUtils
/// </summary>
/// <param name="json">A System.String that contains JSON.</param>
/// <returns>A Newtonsoft.Json.Linq.JToken populated from the string that contains JSON.</returns>
public static JToken Parse(string json)
public static JToken? Parse(string json)
{
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
}
@@ -98,7 +98,7 @@ internal static class JsonUtils
/// </summary>
/// <param name="json">A System.String that contains JSON.</param>
/// <returns>The deserialized object from the JSON string.</returns>
public static object DeserializeObject(string json)
public static object? DeserializeObject(string json)
{
return JsonConvert.DeserializeObject(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
}
@@ -109,21 +109,18 @@ internal static class JsonUtils
/// </summary>
/// <param name="json">A System.String that contains JSON.</param>
/// <returns>The deserialized object from the JSON string.</returns>
public static T DeserializeObject<T>(string json)
public static T? DeserializeObject<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
}
public static T ParseJTokenToObject<T>(object value)
public static T? ParseJTokenToObject<T>(object value)
{
switch (value)
return value switch
{
case JToken tokenValue:
return tokenValue.ToObject<T>();
default:
return default(T);
}
JToken tokenValue => tokenValue.ToObject<T>(),
_ => default
};
}
public static string GenerateDynamicLinqStatement(JToken jsonObject)

View File

@@ -1,42 +1,51 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.RegularExpressions;
using WireMock.Matchers;
namespace WireMock.Util
namespace WireMock.Util;
internal static class StringUtils
{
internal static class StringUtils
public static MatchOperator ParseMatchOperator(string? value)
{
public static bool TryParseQuotedString(string value, out string result, out char quote)
return value != null && Enum.TryParse<MatchOperator>(value, out var matchOperator)
? matchOperator
: MatchOperator.Or;
}
public static bool TryParseQuotedString(string? value, [NotNullWhen(true)] out string? result, out char quote)
{
result = null;
quote = '\0';
if (value == null || value.Length < 2)
{
result = null;
quote = '\0';
if (value == null || value.Length < 2)
{
return false;
}
quote = value[0]; // This can be single or a double quote
if (quote != '"' && quote != '\'')
{
return false;
}
if (value.Last() != quote)
{
return false;
}
try
{
result = Regex.Unescape(value.Substring(1, value.Length - 2));
return true;
}
catch
{
// Ignore Exception, just continue and return false.
}
return false;
}
quote = value[0]; // This can be single or a double quote
if (quote != '"' && quote != '\'')
{
return false;
}
if (value.Last() != quote)
{
return false;
}
try
{
result = Regex.Unescape(value.Substring(1, value.Length - 2));
return true;
}
catch
{
// Ignore Exception, just continue and return false.
}
return false;
}
}