Summary

Class:WireMock.Mapping
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Mapping.cs
Covered lines:36
Uncovered lines:0
Coverable lines:36
Total lines:140
Line coverage:100%
Branch coverage:92.8%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
GetRequestMatchResult(...)0011
.ctor(...)0010
ResponseToAsync()0011

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Mapping.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using JetBrains.Annotations;
 4using WireMock.Matchers.Request;
 5using WireMock.ResponseProviders;
 6
 7namespace WireMock
 8{
 9    /// <summary>
 10    /// The Mapping.
 11    /// </summary>
 12    public class Mapping
 13    {
 14        /// <summary>
 15        /// Gets the unique identifier.
 16        /// </summary>
 58717        public Guid Guid { get; }
 18
 19        /// <summary>
 20        /// Gets the unique title.
 21        /// </summary>
 5822        public string Title { get; }
 23
 24        /// <summary>
 25        /// The full filename path for this mapping (only defined for static mappings).
 26        /// </summary>
 26527        public string Path { get; set; }
 28
 29        /// <summary>
 30        /// Gets the priority.
 31        /// </summary>
 13432        public int Priority { get; }
 33
 34        /// <summary>
 35        /// Scenario.
 36        /// </summary>
 37        [CanBeNull]
 107638        public string Scenario { get; }
 39
 40        /// <summary>
 41        /// Execution state condition for the current mapping.
 42        /// </summary>
 43        [CanBeNull]
 3744        public string ExecutionConditionState { get; }
 45
 46        /// <summary>
 47        /// The next state which will be signaled after the current mapping execution.
 48        /// In case the value is null, state will not be changed.
 49        /// </summary>
 50        [CanBeNull]
 2751        public string NextState { get; }
 52
 53        /// <summary>
 54        /// The Request matcher.
 55        /// </summary>
 30056        public IRequestMatcher RequestMatcher { get; }
 57
 58        /// <summary>
 59        /// The Provider.
 60        /// </summary>
 50761        public IResponseProvider Provider { get; }
 62
 63        /// <summary>
 64        /// Is State started ?
 65        /// </summary>
 766        public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState
 67
 68        /// <summary>
 69        /// Initializes a new instance of the <see cref="Mapping"/> class.
 70        /// </summary>
 71        /// <param name="guid">The unique identifier.</param>
 72        /// <param name="title">The unique title (can be null).</param>
 73        /// <param name="path">The full file path from this mapping title (can be null).</param>
 74        /// <param name="requestMatcher">The request matcher.</param>
 75        /// <param name="provider">The provider.</param>
 76        /// <param name="priority">The priority for this mapping.</param>
 77        /// <param name="scenario">The scenario. [Optional]</param>
 78        /// <param name="executionConditionState">State in which the current mapping can occur. [Optional]</param>
 79        /// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</par
 26580        public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path, IRequestMatcher requestMatcher, IRe
 26581        {
 26582            Guid = guid;
 26583            Title = title;
 26584            Path = path;
 26585            RequestMatcher = requestMatcher;
 26586            Provider = provider;
 26587            Priority = priority;
 26588            Scenario = scenario;
 26589            ExecutionConditionState = executionConditionState;
 26590            NextState = nextState;
 26591        }
 92
 93        /// <summary>
 94        /// The response to.
 95        /// </summary>
 96        /// <param name="requestMessage">The request message.</param>
 97        /// <returns>The <see cref="ResponseMessage"/>.</returns>
 98        public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage)
 5199        {
 51100            return await Provider.ProvideResponseAsync(requestMessage);
 51101        }
 102
 103        /// <summary>
 104        /// Gets the RequestMatchResult based on the RequestMessage.
 105        /// </summary>
 106        /// <param name="requestMessage">The request message.</param>
 107        /// <param name="nextState">The Next State.</param>
 108        /// <returns>The <see cref="RequestMatchResult"/>.</returns>
 109        public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState)
 295110        {
 295111            var result = new RequestMatchResult();
 112
 295113            RequestMatcher.GetMatchingScore(requestMessage, result);
 114
 115            // Only check state if Scenario is defined
 295116            if (Scenario != null)
 30117            {
 30118                var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
 30119                matcher.GetMatchingScore(requestMessage, result);
 120                //// If ExecutionConditionState is null, this means that request is the start from a scenario. So just r
 121                //if (ExecutionConditionState != null)
 122                //{
 123                //    // ExecutionConditionState is not null, so get score for matching with the nextState.
 124                //    var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
 125                //    matcher.GetMatchingScore(requestMessage, result);
 126                //}
 30127            }
 128
 295129            return result;
 295130        }
 131
 132        /// <summary>
 133        /// Gets a value indicating whether this mapping is an Admin Interface.
 134        /// </summary>
 135        /// <value>
 136        /// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>.
 137        /// </value>
 166138        public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider 
 139    }
 140}