diff --git a/WireMock.Net Solution.sln.DotSettings b/WireMock.Net Solution.sln.DotSettings
index a76391a1..d9257030 100644
--- a/WireMock.Net Solution.sln.DotSettings
+++ b/WireMock.Net Solution.sln.DotSettings
@@ -33,6 +33,7 @@
True
True
True
+ True
True
True
True
diff --git a/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs b/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs
index 28d1b1fb..cdb4a3f4 100644
--- a/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs
+++ b/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs
@@ -10,6 +10,7 @@ using Stef.Validation;
using WireMock.Exceptions;
using WireMock.Extensions;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -92,6 +93,17 @@ internal class CSharpCodeMatcher : ICSharpCodeMatcher
return new MatchResult(MatchBehaviourHelper.Convert(MatchBehaviour, score), exception);
}
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}" +
+ $")";
+ }
+
private bool IsMatch(dynamic input, string pattern)
{
var isMatchWithString = input is string;
diff --git a/src/WireMock.Net/Authentication/AzureADAuthenticationMatcher.cs b/src/WireMock.Net/Authentication/AzureADAuthenticationMatcher.cs
index 50aa507a..cc152478 100644
--- a/src/WireMock.Net/Authentication/AzureADAuthenticationMatcher.cs
+++ b/src/WireMock.Net/Authentication/AzureADAuthenticationMatcher.cs
@@ -42,7 +42,7 @@ internal class AzureADAuthenticationMatcher : IStringMatcher
return EmptyArray>.Value;
}
- public MatchOperator MatchOperator { get; } = MatchOperator.Or;
+ public MatchOperator MatchOperator => MatchOperator.Or;
public MatchResult IsMatch(string? input)
{
@@ -76,5 +76,11 @@ internal class AzureADAuthenticationMatcher : IStringMatcher
return new MatchResult(MatchScores.Mismatch, ex);
}
}
+
+ ///
+ public virtual string GetCSharpCodeArguments()
+ {
+ throw new NotImplementedException();
+ }
}
#endif
\ No newline at end of file
diff --git a/src/WireMock.Net/MappingBuilder.cs b/src/WireMock.Net/MappingBuilder.cs
index d2d95419..6e900e1a 100644
--- a/src/WireMock.Net/MappingBuilder.cs
+++ b/src/WireMock.Net/MappingBuilder.cs
@@ -130,7 +130,10 @@ public class MappingBuilder : IMappingBuilder
private IMapping[] GetNonAdminMappings()
{
- return _options.Mappings.Values.Where(m => !m.IsAdminInterface).OrderBy(m => m.UpdatedAt).ToArray();
+ return _options.Mappings.Values
+ .Where(m => !m.IsAdminInterface)
+ .OrderBy(m => m.Guid)
+ .ToArray();
}
private void RegisterMapping(IMapping mapping, bool saveToFile)
diff --git a/src/WireMock.Net/Matchers/ContentTypeMatcher.cs b/src/WireMock.Net/Matchers/ContentTypeMatcher.cs
index 2efdadc2..2a0459c7 100644
--- a/src/WireMock.Net/Matchers/ContentTypeMatcher.cs
+++ b/src/WireMock.Net/Matchers/ContentTypeMatcher.cs
@@ -2,7 +2,10 @@
using System.Net.Http.Headers;
using AnyOfTypes;
+using Stef.Validation;
+using WireMock.Extensions;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -19,7 +22,7 @@ public class ContentTypeMatcher : WildcardMatcher
///
/// The pattern.
/// IgnoreCase (default false)
- public ContentTypeMatcher(AnyOf pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
+ public ContentTypeMatcher(AnyOf pattern, bool ignoreCase = false) : this([pattern], ignoreCase)
{
}
@@ -29,7 +32,8 @@ public class ContentTypeMatcher : WildcardMatcher
/// The match behaviour.
/// The pattern.
/// IgnoreCase (default false)
- public ContentTypeMatcher(MatchBehaviour matchBehaviour, AnyOf pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
+ public ContentTypeMatcher(MatchBehaviour matchBehaviour, AnyOf pattern, bool ignoreCase = false) : this(matchBehaviour,
+ [pattern], ignoreCase)
{
}
@@ -50,7 +54,7 @@ public class ContentTypeMatcher : WildcardMatcher
/// IgnoreCase (default false)
public ContentTypeMatcher(MatchBehaviour matchBehaviour, AnyOf[] patterns, bool ignoreCase = false) : base(matchBehaviour, patterns, ignoreCase)
{
- _patterns = patterns;
+ _patterns = Guard.NotNull(patterns);
}
///
@@ -72,4 +76,15 @@ public class ContentTypeMatcher : WildcardMatcher
///
public override string Name => nameof(ContentTypeMatcher);
+
+ ///
+ public override string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/ExactMatcher.cs b/src/WireMock.Net/Matchers/ExactMatcher.cs
index d72eae42..c210cf59 100644
--- a/src/WireMock.Net/Matchers/ExactMatcher.cs
+++ b/src/WireMock.Net/Matchers/ExactMatcher.cs
@@ -4,7 +4,9 @@ using System;
using System.Linq;
using AnyOfTypes;
using Stef.Validation;
+using WireMock.Extensions;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -86,8 +88,20 @@ public class ExactMatcher : IStringMatcher, IIgnoreCaseMatcher
public MatchOperator MatchOperator { get; }
///
- public string Name => "ExactMatcher";
+ public string Name => nameof(ExactMatcher);
///
public bool IgnoreCase { get; }
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
+ $"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_values)}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/ExactObjectMatcher.cs b/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
index 5150903f..f23ed191 100644
--- a/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
+++ b/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
@@ -72,5 +72,11 @@ public class ExactObjectMatcher : IObjectMatcher
}
///
- public string Name => "ExactObjectMatcher";
+ public string Name => nameof(ExactObjectMatcher);
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return "NotImplemented";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs b/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs
index d1208867..c5e4ac32 100644
--- a/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs
+++ b/src/WireMock.Net/Matchers/FormUrlEncodedMatcher.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using AnyOfTypes;
using Stef.Validation;
+using WireMock.Extensions;
using WireMock.Models;
using WireMock.Util;
@@ -163,4 +164,16 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
///
public MatchOperator MatchOperator { get; }
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
+ $"{MatchOperator.GetFullyQualifiedEnumValue()}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/GraphQLMatcher.cs b/src/WireMock.Net/Matchers/GraphQLMatcher.cs
index 49e72d92..305b973e 100644
--- a/src/WireMock.Net/Matchers/GraphQLMatcher.cs
+++ b/src/WireMock.Net/Matchers/GraphQLMatcher.cs
@@ -156,6 +156,12 @@ public class GraphQLMatcher : IStringMatcher
///
public string Name => nameof(GraphQLMatcher);
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return "NotImplemented";
+ }
+
private static bool TryGetGraphQLRequest(string input, [NotNullWhen(true)] out GraphQLRequest? graphQLRequest)
{
try
diff --git a/src/WireMock.Net/Matchers/IMatcher.cs b/src/WireMock.Net/Matchers/IMatcher.cs
index eed89a45..e6b6c183 100644
--- a/src/WireMock.Net/Matchers/IMatcher.cs
+++ b/src/WireMock.Net/Matchers/IMatcher.cs
@@ -16,4 +16,10 @@ public interface IMatcher
/// Gets the match behaviour.
///
MatchBehaviour MatchBehaviour { get; }
+
+ ///
+ /// Get the C# code arguments.
+ ///
+ ///
+ string GetCSharpCodeArguments();
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/JSONPathMatcher.cs b/src/WireMock.Net/Matchers/JSONPathMatcher.cs
index ade517ed..21f78ea3 100644
--- a/src/WireMock.Net/Matchers/JSONPathMatcher.cs
+++ b/src/WireMock.Net/Matchers/JSONPathMatcher.cs
@@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq;
using Stef.Validation;
using WireMock.Extensions;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -89,7 +90,7 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
Exception? exception = null;
// When input is null or byte[], return Mismatch.
- if (input != null && !(input is byte[]))
+ if (input != null && input is not byte[])
{
try
{
@@ -116,7 +117,18 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
public MatchOperator MatchOperator { get; }
///
- public string Name => "JsonPathMatcher";
+ public string Name => nameof(JsonPathMatcher);
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}" +
+ $")";
+ }
private double IsMatch(JToken jToken)
{
diff --git a/src/WireMock.Net/Matchers/JmesPathMatcher.cs b/src/WireMock.Net/Matchers/JmesPathMatcher.cs
index 0f762755..83b88d19 100644
--- a/src/WireMock.Net/Matchers/JmesPathMatcher.cs
+++ b/src/WireMock.Net/Matchers/JmesPathMatcher.cs
@@ -8,6 +8,7 @@ using Newtonsoft.Json;
using Stef.Validation;
using WireMock.Extensions;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -115,4 +116,15 @@ public class JmesPathMatcher : IStringMatcher, IObjectMatcher
///
public string Name => nameof(JmesPathMatcher);
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/JsonMatcher.cs b/src/WireMock.Net/Matchers/JsonMatcher.cs
index 9a95e557..81b356b2 100644
--- a/src/WireMock.Net/Matchers/JsonMatcher.cs
+++ b/src/WireMock.Net/Matchers/JsonMatcher.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using Stef.Validation;
+using WireMock.Extensions;
using WireMock.Util;
using JsonUtils = WireMock.Util.JsonUtils;
@@ -98,6 +99,18 @@ public class JsonMatcher : IJsonMatcher
return new MatchResult(MatchBehaviourHelper.Convert(MatchBehaviour, score), error);
}
+ ///
+ public virtual string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(Regex)}" +
+ $")";
+ }
+
///
/// Compares the input against the matcher value
///
diff --git a/src/WireMock.Net/Matchers/JsonPartialMatcher.cs b/src/WireMock.Net/Matchers/JsonPartialMatcher.cs
index 8b95691a..ee37345f 100644
--- a/src/WireMock.Net/Matchers/JsonPartialMatcher.cs
+++ b/src/WireMock.Net/Matchers/JsonPartialMatcher.cs
@@ -1,5 +1,8 @@
// Copyright © WireMock.Net
+using WireMock.Extensions;
+using WireMock.Util;
+
namespace WireMock.Matchers;
///
@@ -34,4 +37,16 @@ public class JsonPartialMatcher : AbstractJsonPartialMatcher
var exactStringMatcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, IgnoreCase, MatchOperator.Or, value);
return exactStringMatcher.IsMatch(input).IsPerfect();
}
+
+ ///
+ public override string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(Regex)}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/JsonPartialWildCardMatcher.cs b/src/WireMock.Net/Matchers/JsonPartialWildCardMatcher.cs
index 109a6c72..7fef75a0 100644
--- a/src/WireMock.Net/Matchers/JsonPartialWildCardMatcher.cs
+++ b/src/WireMock.Net/Matchers/JsonPartialWildCardMatcher.cs
@@ -1,5 +1,8 @@
// Copyright © WireMock.Net
+using WireMock.Extensions;
+using WireMock.Util;
+
namespace WireMock.Matchers;
///
@@ -34,4 +37,16 @@ public class JsonPartialWildcardMatcher : AbstractJsonPartialMatcher
var wildcardStringMatcher = new WildcardMatcher(MatchBehaviour.AcceptOnMatch, value, IgnoreCase);
return wildcardStringMatcher.IsMatch(input).IsPerfect();
}
+
+ ///
+ public override string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
+ $"{CSharpFormatter.ToCSharpBooleanLiteral(Regex)}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/LinqMatcher.cs b/src/WireMock.Net/Matchers/LinqMatcher.cs
index 488e2c38..cb82f3b3 100644
--- a/src/WireMock.Net/Matchers/LinqMatcher.cs
+++ b/src/WireMock.Net/Matchers/LinqMatcher.cs
@@ -9,6 +9,7 @@ using Stef.Validation;
using WireMock.Extensions;
using WireMock.Json;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -136,4 +137,15 @@ public class LinqMatcher : IObjectMatcher, IStringMatcher
///
public string Name => nameof(LinqMatcher);
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
+ $"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
+ $"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/MimePartMatcher.cs b/src/WireMock.Net/Matchers/MimePartMatcher.cs
index 926cc1c3..6b41413b 100644
--- a/src/WireMock.Net/Matchers/MimePartMatcher.cs
+++ b/src/WireMock.Net/Matchers/MimePartMatcher.cs
@@ -3,6 +3,7 @@
#if MIMEKIT
using System;
using MimeKit;
+using WireMock.Extensions;
using WireMock.Matchers;
using WireMock.Matchers.Helpers;
using WireMock.Models;
@@ -60,13 +61,13 @@ public class MimePartMatcher : IMatcher
ContentTransferEncodingMatcher = contentTransferEncodingMatcher;
ContentMatcher = contentMatcher;
- _funcs = new[]
- {
+ _funcs =
+ [
mp => ContentTypeMatcher?.IsMatch(GetContentTypeAsString(mp.ContentType)) ?? MatchScores.Perfect,
mp => ContentDispositionMatcher?.IsMatch(mp.ContentDisposition.ToString().Replace("Content-Disposition: ", string.Empty)) ?? MatchScores.Perfect,
mp => ContentTransferEncodingMatcher?.IsMatch(mp.ContentTransferEncoding.ToString().ToLowerInvariant()) ?? MatchScores.Perfect,
MatchOnContent
- };
+ ];
}
///
@@ -94,6 +95,12 @@ public class MimePartMatcher : IMatcher
return new MatchResult(MatchBehaviourHelper.Convert(MatchBehaviour, score), exception);
}
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return "NotImplemented";
+ }
+
private MatchResult MatchOnContent(MimePart mimePart)
{
if (ContentMatcher == null)
diff --git a/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs b/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs
index a9e7d0ea..e159b65d 100644
--- a/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs
+++ b/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs
@@ -3,7 +3,9 @@
using System;
using System.Linq;
using AnyOfTypes;
+using WireMock.Extensions;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers;
@@ -70,5 +72,14 @@ public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher
}
///
- public MatchOperator MatchOperator { get; } = MatchOperator.Or;
+ public MatchOperator MatchOperator => MatchOperator.Or;
+
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return $"new {Name}" +
+ $"(" +
+ $"{MatchBehaviour.GetFullyQualifiedEnumValue()}" +
+ $")";
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/ProtoBufMatcher.cs b/src/WireMock.Net/Matchers/ProtoBufMatcher.cs
index 30257a7d..ee109d6a 100644
--- a/src/WireMock.Net/Matchers/ProtoBufMatcher.cs
+++ b/src/WireMock.Net/Matchers/ProtoBufMatcher.cs
@@ -89,6 +89,12 @@ public class ProtoBufMatcher : IProtoBufMatcher
return DecodeAsync(input, false, cancellationToken);
}
+ ///
+ public string GetCSharpCodeArguments()
+ {
+ return "NotImplemented";
+ }
+
private async Task