| | | 1 | | using System.Linq; |
| | | 2 | | using JetBrains.Annotations; |
| | | 3 | | using WireMock.Validation; |
| | | 4 | | |
| | | 5 | | namespace WireMock.Matchers.Request |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// The request verb matcher. |
| | | 9 | | /// </summary> |
| | | 10 | | internal class RequestMessageMethodMatcher : IRequestMatcher |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// The methods |
| | | 14 | | /// </summary> |
| | 15 | 15 | | public string[] Methods { get; } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <param name="methods"> |
| | | 21 | | /// The verb. |
| | | 22 | | /// </param> |
| | 22 | 23 | | public RequestMessageMethodMatcher([NotNull] params string[] methods) |
| | 22 | 24 | | { |
| | 22 | 25 | | Check.NotNull(methods, nameof(methods)); |
| | 44 | 26 | | Methods = methods.Select(v => v.ToLower()).ToArray(); |
| | 22 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Determines whether the specified RequestMessage is match. |
| | | 31 | | /// </summary> |
| | | 32 | | /// <param name="requestMessage">The RequestMessage.</param> |
| | | 33 | | /// <param name="requestMatchResult">The RequestMatchResult.</param> |
| | | 34 | | /// <returns> |
| | | 35 | | /// A value between 0.0 - 1.0 of the similarity. |
| | | 36 | | /// </returns> |
| | | 37 | | public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) |
| | 15 | 38 | | { |
| | 15 | 39 | | double score = IsMatch(requestMessage); |
| | 15 | 40 | | requestMatchResult.TotalScore += score; |
| | | 41 | | |
| | 15 | 42 | | requestMatchResult.TotalNumber++; |
| | | 43 | | |
| | 15 | 44 | | return score; |
| | 15 | 45 | | } |
| | | 46 | | |
| | | 47 | | private double IsMatch(RequestMessage requestMessage) |
| | 15 | 48 | | { |
| | 15 | 49 | | return MatchScores.ToScore(Methods.Contains(requestMessage.Method)); |
| | 15 | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |