Summary

Class:WireMock.Server.RespondWithAProvider
Assembly:WireMock.Net
File(s):C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Server\RespondWithAProvider.cs
Covered lines:42
Uncovered lines:4
Coverable lines:46
Total lines:115
Line coverage:91.3%
Branch coverage:50%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
RespondWith(...)0010
WithGuid(...)0010
WithGuid(...)0010
WithTitle(...)0010
WithPath(...)0010
AtPriority(...)0010
InScenario(...)0010
WhenStateIs(...)000.7140.5
WillSetStateTo(...)000.7140.5
.ctor(...)0010

File(s)

C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Server\RespondWithAProvider.cs

#LineLine coverage
 1using System;
 2using WireMock.Matchers.Request;
 3using WireMock.ResponseProviders;
 4
 5namespace WireMock.Server
 6{
 7    /// <summary>
 8    /// The respond with a provider.
 9    /// </summary>
 10    internal class RespondWithAProvider : IRespondWithAProvider
 11    {
 12        private int _priority;
 13        private string _title;
 14        private string _path;
 15        private string _executionConditionState;
 16        private string _nextState;
 17        private string _scenario;
 18        private readonly RegistrationCallback _registrationCallback;
 19        private readonly IRequestMatcher _requestMatcher;
 20
 52221        public Guid Guid { get; private set; } = Guid.NewGuid();
 22
 23        /// <summary>
 24        /// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
 25        /// </summary>
 26        /// <param name="registrationCallback">The registration callback.</param>
 27        /// <param name="requestMatcher">The request matcher.</param>
 24928        public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestMatcher)
 24929        {
 24930            _registrationCallback = registrationCallback;
 24931            _requestMatcher = requestMatcher;
 24932        }
 33
 34        /// <summary>
 35        /// The respond with.
 36        /// </summary>
 37        /// <param name="provider">The provider.</param>
 38        public void RespondWith(IResponseProvider provider)
 24939        {
 24940            _registrationCallback(new Mapping(Guid, _title, _path, _requestMatcher, provider, _priority, _scenario, _exe
 24941        }
 42
 43        /// <see cref="IRespondWithAProvider.WithGuid(string)"/>
 44        public IRespondWithAProvider WithGuid(string guid)
 245        {
 246            return WithGuid(Guid.Parse(guid));
 247        }
 48
 49        /// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
 50        public IRespondWithAProvider WithGuid(Guid guid)
 1451        {
 1452            Guid = guid;
 53
 1454            return this;
 1455        }
 56
 57        /// <see cref="IRespondWithAProvider.WithTitle"/>
 58        public IRespondWithAProvider WithTitle(string title)
 459        {
 460            _title = title;
 61
 462            return this;
 463        }
 64
 65        /// <see cref="IRespondWithAProvider.WithPath"/>
 66        public IRespondWithAProvider WithPath(string path)
 1067        {
 1068            _path = path;
 69
 1070            return this;
 1071        }
 72
 73        /// <see cref="IRespondWithAProvider.AtPriority"/>
 74        public IRespondWithAProvider AtPriority(int priority)
 22175        {
 22176            _priority = priority;
 77
 22178            return this;
 22179        }
 80
 81        /// <see cref="IRespondWithAProvider.InScenario(string)"/>
 82        public IRespondWithAProvider InScenario(string scenario)
 1083        {
 1084            _scenario = scenario;
 85
 1086            return this;
 1087        }
 88
 89        /// <see cref="IRespondWithAProvider.WhenStateIs"/>
 90        public IRespondWithAProvider WhenStateIs(string state)
 691        {
 692            if (string.IsNullOrEmpty(_scenario))
 093            {
 094                throw new NotSupportedException("Unable to set state condition when no scenario is defined.");
 95            }
 96
 697            _executionConditionState = state;
 98
 699            return this;
 6100        }
 101
 102        /// <see cref="IRespondWithAProvider.WillSetStateTo"/>
 103        public IRespondWithAProvider WillSetStateTo(string state)
 5104        {
 5105            if (string.IsNullOrEmpty(_scenario))
 0106            {
 0107                throw new NotSupportedException("Unable to set next state when no scenario is defined.");
 108            }
 109
 5110            _nextState = state;
 111
 5112            return this;
 5113        }
 114    }
 115}