| | | 1 | | using System; |
| | | 2 | | using System.Linq; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | using WireMock.Validation; |
| | | 5 | | |
| | | 6 | | namespace WireMock.Matchers.Request |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The request verb matcher. |
| | | 10 | | /// </summary> |
| | | 11 | | internal class RequestMessageMethodMatcher : IRequestMatcher |
| | | 12 | | { |
| | | 13 | | private readonly MatchBehaviour _matchBehaviour; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// The methods |
| | | 17 | | /// </summary> |
| | 287 | 18 | | public string[] Methods { get; } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="matchBehaviour">The match behaviour.</param> |
| | | 24 | | /// <param name="methods">The methods.</param> |
| | 254 | 25 | | public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods) |
| | 254 | 26 | | { |
| | 254 | 27 | | Check.NotNull(methods, nameof(methods)); |
| | 254 | 28 | | _matchBehaviour = matchBehaviour; |
| | | 29 | | |
| | 254 | 30 | | Methods = methods; |
| | 254 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/> |
| | | 34 | | public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) |
| | 286 | 35 | | { |
| | 286 | 36 | | double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage)); |
| | 286 | 37 | | return requestMatchResult.AddScore(GetType(), score); |
| | 286 | 38 | | } |
| | | 39 | | |
| | | 40 | | private double IsMatch(RequestMessage requestMessage) |
| | 286 | 41 | | { |
| | 286 | 42 | | return MatchScores.ToScore(Methods.Contains(requestMessage.Method, StringComparer.OrdinalIgnoreCase)); |
| | 286 | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |