| | | 1 | | using System.Linq; |
| | | 2 | | using JetBrains.Annotations; |
| | | 3 | | using WireMock.Validation; |
| | | 4 | | |
| | | 5 | | namespace WireMock.Matchers |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// ExactMatcher |
| | | 9 | | /// </summary> |
| | | 10 | | /// <seealso cref="IStringMatcher" /> |
| | | 11 | | public class ExactMatcher : IStringMatcher |
| | | 12 | | { |
| | | 13 | | private readonly string[] _values; |
| | | 14 | | |
| | | 15 | | /// <inheritdoc cref="IMatcher.MatchBehaviour"/> |
| | 23 | 16 | | public MatchBehaviour MatchBehaviour { get; } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="ExactMatcher"/> class. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="values">The values.</param> |
| | 15 | 22 | | public ExactMatcher([NotNull] params string[] values) : this(MatchBehaviour.AcceptOnMatch, values) |
| | 15 | 23 | | { |
| | 15 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes a new instance of the <see cref="ExactMatcher"/> class. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="matchBehaviour">The match behaviour.</param> |
| | | 30 | | /// <param name="values">The values.</param> |
| | 39 | 31 | | public ExactMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] values) |
| | 39 | 32 | | { |
| | 39 | 33 | | Check.HasNoNulls(values, nameof(values)); |
| | | 34 | | |
| | 39 | 35 | | _values = values; |
| | 39 | 36 | | MatchBehaviour = matchBehaviour; |
| | 39 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <inheritdoc cref="IStringMatcher.IsMatch"/> |
| | | 40 | | public double IsMatch(string input) |
| | 23 | 41 | | { |
| | 70 | 42 | | return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_values.Select(value => value.Equals |
| | 23 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <inheritdoc cref="IStringMatcher.GetPatterns"/> |
| | | 46 | | public string[] GetPatterns() |
| | 3 | 47 | | { |
| | 3 | 48 | | return _values; |
| | 3 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <inheritdoc cref="IMatcher.Name"/> |
| | 1 | 52 | | public string Name => "ExactMatcher"; |
| | | 53 | | } |
| | | 54 | | } |