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:100%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
GetRequestMatchResult(...)22100100
ResponseToAsync()30100100

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>
 25917        public Guid Guid { get; }
 18
 19        /// <summary>
 20        /// Gets the unique title.
 21        /// </summary>
 5022        public string Title { get; }
 23
 24        /// <summary>
 25        /// The full filename path for this mapping (only defined for static mappings).
 26        /// </summary>
 10627        public string Path { get; set; }
 28
 29        /// <summary>
 30        /// Gets the priority.
 31        /// </summary>
 17132        public int Priority { get; }
 33
 34        /// <summary>
 35        /// Scenario.
 36        /// </summary>
 37        [CanBeNull]
 55138        public string Scenario { get; }
 39
 40        /// <summary>
 41        /// Execution state condition for the current mapping.
 42        /// </summary>
 43        [CanBeNull]
 1744        public object 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]
 951        public object NextState { get; }
 52
 53        /// <summary>
 54        /// The Request matcher.
 55        /// </summary>
 15356        public IRequestMatcher RequestMatcher { get; }
 57
 58        /// <summary>
 59        /// The Provider.
 60        /// </summary>
 44961        public IResponseProvider Provider { get; }
 62
 63        /// <summary>
 64        /// Is State started ?
 65        /// </summary>
 366        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
 10680        public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path, IRequestMatcher requestMatcher, IRe
 10681        {
 10682            Guid = guid;
 10683            Title = title;
 10684            Path = path;
 10685            RequestMatcher = requestMatcher;
 10686            Provider = provider;
 10687            Priority = priority;
 10688            Scenario = scenario;
 10689            ExecutionConditionState = executionConditionState;
 10690            NextState = nextState;
 10691        }
 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)
 4699        {
 46100            return await Provider.ProvideResponseAsync(requestMessage);
 46101        }
 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] object nextState)
 150110        {
 150111            var result = new RequestMatchResult();
 112
 150113            RequestMatcher.GetMatchingScore(requestMessage, result);
 114
 115            // Only check state if Scenario is defined
 150116             if (Scenario != null)
 14117            {
 14118                var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
 14119                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                //}
 14127            }
 128
 150129            return result;
 150130        }
 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>
 139138        public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider 
 139    }
 140}