mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-30 05:41:46 +02:00
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using JetBrains.Annotations;
|
|
using WireMock.Validation;
|
|
|
|
namespace WireMock.Matchers.Request
|
|
{
|
|
/// <summary>
|
|
/// The request verb matcher.
|
|
/// </summary>
|
|
internal class RequestMessageMethodMatcher : IRequestMatcher
|
|
{
|
|
private readonly MatchBehaviour _matchBehaviour;
|
|
|
|
/// <summary>
|
|
/// The methods
|
|
/// </summary>
|
|
public string[] Methods { get; }
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class.
|
|
/// </summary>
|
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
/// <param name="methods">The methods.</param>
|
|
public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods)
|
|
{
|
|
Check.NotNull(methods, nameof(methods));
|
|
_matchBehaviour = matchBehaviour;
|
|
|
|
Methods = methods;
|
|
}
|
|
|
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
|
{
|
|
double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
|
return requestMatchResult.AddScore(GetType(), score);
|
|
}
|
|
|
|
private double IsMatch(IRequestMessage requestMessage)
|
|
{
|
|
return MatchScores.ToScore(Methods.Contains(requestMessage.Method, StringComparer.OrdinalIgnoreCase));
|
|
}
|
|
}
|
|
} |