using System.Linq;
using AnyOfTypes;
using Stef.Validation;
using WireMock.Extensions;
using WireMock.Models;
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(params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, false, MatchOperator.Or, values)
{
}
///
/// Initializes a new instance of the class.
///
/// The match behaviour.
/// Throw an exception when the internal matching fails because of invalid input.
/// The to use. (default = "Or")
/// The values.
public ExactMatcher(
MatchBehaviour matchBehaviour,
bool throwException = false,
MatchOperator matchOperator = MatchOperator.Or,
params AnyOf[] values)
{
_values = Guard.NotNull(values);
MatchBehaviour = matchBehaviour;
ThrowException = throwException;
MatchOperator = matchOperator;
}
///
public double IsMatch(string? input)
{
double score = MatchScores.ToScore(_values.Select(v => v.GetPattern() == input).ToArray(), MatchOperator);
return MatchBehaviourHelper.Convert(MatchBehaviour, score);
}
///
public AnyOf[] GetPatterns()
{
return _values;
}
///
public MatchOperator MatchOperator { get; }
///
public string Name => "ExactMatcher";
}