| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | using WireMock.Admin.Mappings; |
| | | 5 | | using WireMock.Matchers; |
| | | 6 | | |
| | | 7 | | namespace WireMock.Serialization |
| | | 8 | | { |
| | | 9 | | internal static class MatcherMapper |
| | | 10 | | { |
| | | 11 | | public static MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers) |
| | 2 | 12 | | { |
| | 4 | 13 | | return matchers?.Select(Map).Where(x => x != null).ToArray(); |
| | 2 | 14 | | } |
| | | 15 | | |
| | | 16 | | public static MatcherModel Map([CanBeNull] IMatcher matcher) |
| | 5 | 17 | | { |
| | 5 | 18 | | if (matcher == null) |
| | 1 | 19 | | { |
| | 1 | 20 | | return null; |
| | | 21 | | } |
| | | 22 | | |
| | 4 | 23 | | string[] patterns = matcher is IStringMatcher stringMatcher ? stringMatcher.GetPatterns() : new string[0]; |
| | 4 | 24 | | bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)n |
| | | 25 | | |
| | 4 | 26 | | return new MatcherModel |
| | 4 | 27 | | { |
| | 4 | 28 | | IgnoreCase = ignorecase, |
| | 4 | 29 | | Name = matcher.GetName(), |
| | 4 | 30 | | Pattern = patterns.Length == 1 ? patterns.First() : null, |
| | 4 | 31 | | Patterns = patterns.Length > 1 ? patterns : null |
| | 4 | 32 | | }; |
| | 5 | 33 | | } |
| | | 34 | | } |
| | | 35 | | } |