using System; using System.Linq; using AnyOfTypes; using Stef.Validation; using WireMock.Models; namespace WireMock.Matchers; /// /// ExactMatcher /// /// and public class ExactMatcher : IStringMatcher, IIgnoreCaseMatcher { private readonly AnyOf[] _values; /// public MatchBehaviour MatchBehaviour { get; } /// public bool ThrowException { get; } /// /// Initializes a new instance of the class. /// /// The values. public ExactMatcher(params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, false, false, MatchOperator.Or, values) { } /// /// Initializes a new instance of the class. /// /// Ignore the case from the pattern(s). /// The values. public ExactMatcher(bool ignoreCase, params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, ignoreCase, false, MatchOperator.Or, values) { } /// /// Initializes a new instance of the class. /// /// The match behaviour. /// Ignore the case from the pattern(s). /// Throw an exception when the internal matching fails because of invalid input. /// The to use. (default = "Or") /// The values. public ExactMatcher( MatchBehaviour matchBehaviour, bool ignoreCase = false, bool throwException = false, MatchOperator matchOperator = MatchOperator.Or, params AnyOf[] values) { _values = Guard.NotNull(values); MatchBehaviour = matchBehaviour; ThrowException = throwException; IgnoreCase = ignoreCase; MatchOperator = matchOperator; } /// public double IsMatch(string? input) { Func equals = IgnoreCase ? pattern => string.Equals(pattern, input, StringComparison.OrdinalIgnoreCase) : pattern => pattern == input; double score = MatchScores.ToScore(_values.Select(v => equals(v)).ToArray(), MatchOperator); return MatchBehaviourHelper.Convert(MatchBehaviour, score); } /// public AnyOf[] GetPatterns() { return _values; } /// public MatchOperator MatchOperator { get; } /// public string Name => "ExactMatcher"; /// public bool IgnoreCase { get; } }