| | | 1 | | using JetBrains.Annotations; |
| | | 2 | | |
| | | 3 | | namespace WireMock.Matchers.Request |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// The scenario and state matcher. |
| | | 7 | | /// </summary> |
| | | 8 | | internal class RequestMessageScenarioAndStateMatcher : IRequestMatcher |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Execution state condition for the current mapping. |
| | | 12 | | /// </summary> |
| | | 13 | | [CanBeNull] |
| | | 14 | | private readonly string _executionConditionState; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// The next state which will be signaled after the current mapping execution. |
| | | 18 | | /// In case the value is null state will not be changed. |
| | | 19 | | /// </summary> |
| | | 20 | | [CanBeNull] |
| | | 21 | | private readonly string _nextState; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new instance of the <see cref="RequestMessageScenarioAndStateMatcher"/> class. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="nextState">The next state.</param> |
| | | 27 | | /// <param name="executionConditionState">Execution state condition for the current mapping.</param> |
| | 30 | 28 | | public RequestMessageScenarioAndStateMatcher([CanBeNull] string nextState, [CanBeNull] string executionCondition |
| | 30 | 29 | | { |
| | 30 | 30 | | _nextState = nextState; |
| | 30 | 31 | | _executionConditionState = executionConditionState; |
| | 30 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) |
| | 30 | 36 | | { |
| | 30 | 37 | | double score = IsMatch(); |
| | 30 | 38 | | return requestMatchResult.AddScore(GetType(), score); |
| | 30 | 39 | | } |
| | | 40 | | |
| | | 41 | | private double IsMatch() |
| | 30 | 42 | | { |
| | 30 | 43 | | return Equals(_executionConditionState, _nextState) ? MatchScores.Perfect : MatchScores.Mismatch; |
| | 30 | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |