Added support of custom matchers in static mappings (#713)

* Added support of custom matchers in static mappings

* Fixed code style issues

* Fixed naming and code style

* added empty line

* Ignore serialization of CustomMatcherMappings property in WireMockServerSettings

* Added integration tests for CustomMatcherMappings
This commit is contained in:
Levan Nozadze
2022-01-17 19:04:37 +04:00
committed by GitHub
parent 60bdc06d29
commit 6b393ebc1d
7 changed files with 321 additions and 0 deletions

View File

@@ -105,6 +105,11 @@ namespace WireMock.Serialization
return new SimMetricsMatcher(matchBehaviour, stringPatterns, type, throwExceptionWhenMatcherFails);
default:
if (_settings.CustomMatcherMappings != null && _settings.CustomMatcherMappings.ContainsKey(matcherName))
{
return _settings.CustomMatcherMappings[matcherName](matcher);
}
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
}
}

View File

@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using HandlebarsDotNet;
using JetBrains.Annotations;
using Newtonsoft.Json;
using WireMock.Admin.Mappings;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
@@ -229,5 +232,11 @@ namespace WireMock.Settings
/// </summary>
[PublicAPI]
bool? SaveUnmatchedRequests { get; set; }
/// <summary>
/// Custom matcher mappings for static mappings
/// </summary>
[PublicAPI, JsonIgnore]
IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
}
}

View File

@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using HandlebarsDotNet;
using JetBrains.Annotations;
using Newtonsoft.Json;
using WireMock.Admin.Mappings;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
#if USE_ASPNETCORE
using Microsoft.Extensions.DependencyInjection;
#endif
@@ -158,5 +161,9 @@ namespace WireMock.Settings
/// <inheritdoc cref="IWireMockServerSettings.SaveUnmatchedRequests"/>
[PublicAPI]
public bool? SaveUnmatchedRequests { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.CustomMatcherMappings"/>
[PublicAPI, JsonIgnore]
public IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
}
}