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:138
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 : IMapping
 13    {
 14        /// <inheritdoc cref="IMapping.Guid" />
 54115        public Guid Guid { get; }
 16
 17        /// <summary>
 18        /// Gets the unique title.
 19        /// </summary>
 4220        public string Title { get; }
 21
 22        /// <summary>
 23        /// The full filename path for this mapping (only defined for static mappings).
 24        /// </summary>
 25025        public string Path { get; set; }
 26
 27        /// <summary>
 28        /// Gets the priority.
 29        /// </summary>
 11830        public int Priority { get; }
 31
 32        /// <summary>
 33        /// Scenario.
 34        /// </summary>
 35        [CanBeNull]
 101436        public string Scenario { get; }
 37
 38        /// <summary>
 39        /// Execution state condition for the current mapping.
 40        /// </summary>
 41        [CanBeNull]
 3742        public string ExecutionConditionState { get; }
 43
 44        /// <summary>
 45        /// The next state which will be signaled after the current mapping execution.
 46        /// In case the value is null, state will not be changed.
 47        /// </summary>
 48        [CanBeNull]
 2849        public string NextState { get; }
 50
 51        /// <summary>
 52        /// The Request matcher.
 53        /// </summary>
 28454        public IRequestMatcher RequestMatcher { get; }
 55
 56        /// <summary>
 57        /// The Provider.
 58        /// </summary>
 32359        public IResponseProvider Provider { get; }
 60
 61        /// <summary>
 62        /// Is State started ?
 63        /// </summary>
 864        public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState
 65
 66        /// <summary>
 67        /// Initializes a new instance of the <see cref="Mapping"/> class.
 68        /// </summary>
 69        /// <param name="guid">The unique identifier.</param>
 70        /// <param name="title">The unique title (can be null).</param>
 71        /// <param name="path">The full file path from this mapping title (can be null).</param>
 72        /// <param name="requestMatcher">The request matcher.</param>
 73        /// <param name="provider">The provider.</param>
 74        /// <param name="priority">The priority for this mapping.</param>
 75        /// <param name="scenario">The scenario. [Optional]</param>
 76        /// <param name="executionConditionState">State in which the current mapping can occur. [Optional]</param>
 77        /// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</par
 25078        public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path, IRequestMatcher requestMatcher, IRe
 25079        {
 25080            Guid = guid;
 25081            Title = title;
 25082            Path = path;
 25083            RequestMatcher = requestMatcher;
 25084            Provider = provider;
 25085            Priority = priority;
 25086            Scenario = scenario;
 25087            ExecutionConditionState = executionConditionState;
 25088            NextState = nextState;
 25089        }
 90
 91        /// <summary>
 92        /// The response to.
 93        /// </summary>
 94        /// <param name="requestMessage">The request message.</param>
 95        /// <returns>The <see cref="ResponseMessage"/>.</returns>
 96        public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage)
 3597        {
 3598            return await Provider.ProvideResponseAsync(requestMessage);
 3599        }
 100
 101        /// <summary>
 102        /// Gets the RequestMatchResult based on the RequestMessage.
 103        /// </summary>
 104        /// <param name="requestMessage">The request message.</param>
 105        /// <param name="nextState">The Next State.</param>
 106        /// <returns>The <see cref="RequestMatchResult"/>.</returns>
 107        public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState)
 279108        {
 279109            var result = new RequestMatchResult();
 110
 279111            RequestMatcher.GetMatchingScore(requestMessage, result);
 112
 113            // Only check state if Scenario is defined
 279114            if (Scenario != null)
 30115            {
 30116                var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
 30117                matcher.GetMatchingScore(requestMessage, result);
 118                //// If ExecutionConditionState is null, this means that request is the start from a scenario. So just r
 119                //if (ExecutionConditionState != null)
 120                //{
 121                //    // ExecutionConditionState is not null, so get score for matching with the nextState.
 122                //    var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
 123                //    matcher.GetMatchingScore(requestMessage, result);
 124                //}
 30125            }
 126
 279127            return result;
 279128        }
 129
 130        /// <summary>
 131        /// Gets a value indicating whether this mapping is an Admin Interface.
 132        /// </summary>
 133        /// <value>
 134        /// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>.
 135        /// </value>
 110136        public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider 
 137    }
 138}