using System.Linq; using AnyOfTypes; using JetBrains.Annotations; using WireMock.Extensions; using WireMock.Models; using WireMock.Validation; namespace WireMock.Matchers { /// /// ExactMatcher /// /// public class ExactMatcher : IStringMatcher { private readonly AnyOf[] _values; /// public MatchBehaviour MatchBehaviour { get; } /// public bool ThrowException { get; } /// /// Initializes a new instance of the class. /// /// The values. public ExactMatcher([NotNull] params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, false, values) { } /// /// Initializes a new instance of the class. /// /// The match behaviour. /// Throw an exception when the internal matching fails because of invalid input. /// The values. public ExactMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf[] values) { Check.NotNull(values, nameof(values)); MatchBehaviour = matchBehaviour; ThrowException = throwException; _values = values; } /// public double IsMatch(string input) { if (_values.Length == 1) { return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_values[0].GetPattern() == input)); } return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_values.Select(v => v.GetPattern()).Contains(input))); } /// public AnyOf[] GetPatterns() { return _values; } /// public string Name => "ExactMatcher"; } }