Summary

Class:WireMock.Server.RespondWithAProvider
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\RespondWithAProvider.cs
Covered lines:42
Uncovered lines:4
Coverable lines:46
Total lines:120
Line coverage:91.3%
Branch coverage:66.6%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
RespondWith(...)22100100
WithGuid(...)10100100
WithGuid(...)10100100
WithTitle(...)10100100
WithPath(...)10100100
AtPriority(...)10100100
InScenario(...)10100100
WhenStateIs(...)2271.4366.67
WillSetStateTo(...)2271.4366.67

File(s)

C:\Users\azureuser\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 Guid? _guid;
 14        private string _title;
 15        private string _path;
 16        private object _executionConditionState;
 17        private object _nextState;
 18        private string _scenario;
 19        private readonly RegistrationCallback _registrationCallback;
 20        private readonly IRequestMatcher _requestMatcher;
 21
 22        /// <summary>
 23        /// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
 24        /// </summary>
 25        /// <param name="registrationCallback">The registration callback.</param>
 26        /// <param name="requestMatcher">The request matcher.</param>
 10327        public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestMatcher)
 10328        {
 10329            _registrationCallback = registrationCallback;
 10330            _requestMatcher = requestMatcher;
 10331        }
 32
 33        /// <summary>
 34        /// The respond with.
 35        /// </summary>
 36        /// <param name="provider">The provider.</param>
 37        public void RespondWith(IResponseProvider provider)
 10338        {
 10339             var mappingGuid = _guid ?? Guid.NewGuid();
 10340            _registrationCallback(new Mapping(mappingGuid, _title, _path, _requestMatcher, provider, _priority, _scenari
 10341        }
 42
 43        /// <see cref="IRespondWithAProvider.WithGuid(string)"/>
 44        public IRespondWithAProvider WithGuid(string guid)
 145        {
 146            return WithGuid(Guid.Parse(guid));
 147        }
 48
 49        /// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
 50        public IRespondWithAProvider WithGuid(Guid guid)
 851        {
 852            _guid = guid;
 53
 854            return this;
 855        }
 56
 57        /// <see cref="IRespondWithAProvider.WithTitle"/>
 58        public IRespondWithAProvider WithTitle(string title)
 359        {
 360            _title = title;
 61
 362            return this;
 363        }
 64
 65        /// <see cref="IRespondWithAProvider.WithPath"/>
 66        public IRespondWithAProvider WithPath(string path)
 467        {
 468            _path = path;
 69
 470            return this;
 471        }
 72
 73        /// <see cref="IRespondWithAProvider.AtPriority"/>
 74        public IRespondWithAProvider AtPriority(int priority)
 775        {
 776            _priority = priority;
 77
 778            return this;
 779        }
 80
 81        /// <see cref="IRespondWithAProvider.InScenario(string)"/>
 82        public IRespondWithAProvider InScenario(string scenario)
 683        {
 684            _scenario = scenario;
 85
 686            return this;
 687        }
 88
 89        /// <see cref="IRespondWithAProvider.WhenStateIs"/>
 90        public IRespondWithAProvider WhenStateIs(object state)
 491        {
 492             if (string.IsNullOrEmpty(_scenario))
 093            {
 094                throw new NotSupportedException("Unable to set state condition when no scenario is defined.");
 95            }
 96
 97            //if (_nextState != null)
 98            //{
 99            //    throw new NotSupportedException("Unable to set state condition when next state is defined.");
 100            //}
 101
 4102            _executionConditionState = state;
 103
 4104            return this;
 4105        }
 106
 107        /// <see cref="IRespondWithAProvider.WillSetStateTo"/>
 108        public IRespondWithAProvider WillSetStateTo(object state)
 3109        {
 3110             if (string.IsNullOrEmpty(_scenario))
 0111            {
 0112                throw new NotSupportedException("Unable to set next state when no scenario is defined.");
 113            }
 114
 3115            _nextState = state;
 116
 3117            return this;
 3118        }
 119    }
 120}