| | | 1 | | using System; |
| | | 2 | | using JetBrains.Annotations; |
| | | 3 | | using SimMetrics.Net; |
| | | 4 | | using WireMock.Admin.Mappings; |
| | | 5 | | using WireMock.Matchers; |
| | | 6 | | |
| | | 7 | | namespace WireMock.Serialization |
| | | 8 | | { |
| | | 9 | | internal static class MatcherModelMapper |
| | | 10 | | { |
| | | 11 | | public static IMatcher Map([CanBeNull] MatcherModel matcher) |
| | 15 | 12 | | { |
| | 15 | 13 | | if (matcher == null) |
| | 1 | 14 | | { |
| | 1 | 15 | | return null; |
| | | 16 | | } |
| | | 17 | | |
| | 14 | 18 | | string[] parts = matcher.Name.Split('.'); |
| | 14 | 19 | | string matcherName = parts[0]; |
| | 14 | 20 | | string matcherType = parts.Length > 1 ? parts[1] : null; |
| | | 21 | | |
| | 14 | 22 | | string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern }; |
| | | 23 | | |
| | 14 | 24 | | switch (matcherName) |
| | | 25 | | { |
| | | 26 | | case "ExactMatcher": |
| | 6 | 27 | | return new ExactMatcher(patterns); |
| | | 28 | | |
| | | 29 | | case "RegexMatcher": |
| | 1 | 30 | | return new RegexMatcher(patterns, matcher.IgnoreCase == true); |
| | | 31 | | |
| | | 32 | | case "JsonPathMatcher": |
| | 0 | 33 | | return new JsonPathMatcher(patterns); |
| | | 34 | | |
| | | 35 | | case "XPathMatcher": |
| | 0 | 36 | | return new XPathMatcher(matcher.Pattern); |
| | | 37 | | |
| | | 38 | | case "WildcardMatcher": |
| | 3 | 39 | | return new WildcardMatcher(patterns, matcher.IgnoreCase == true); |
| | | 40 | | |
| | | 41 | | case "SimMetricsMatcher": |
| | 3 | 42 | | SimMetricType type = SimMetricType.Levenstein; |
| | 3 | 43 | | if (!string.IsNullOrEmpty(matcherType) && !Enum.TryParse(matcherType, out type)) |
| | 1 | 44 | | { |
| | 1 | 45 | | throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not suppo |
| | | 46 | | } |
| | | 47 | | |
| | 2 | 48 | | return new SimMetricsMatcher(matcher.Pattern, type); |
| | | 49 | | |
| | | 50 | | default: |
| | 1 | 51 | | throw new NotSupportedException($"Matcher '{matcherName}' is not supported."); |
| | | 52 | | } |
| | 13 | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |