Summary

Class:WireMock.RequestBuilders.Request
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\RequestBuilders\Request.cs
Covered lines:150
Uncovered lines:29
Coverable lines:179
Total lines:409
Line coverage:83.7%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
Create()10100100
.ctor(...)10100100
GetRequestMessageMatchers()20100100
GetRequestMessageMatcher()20100100
WithClientIP(...)10100100
WithClientIP(...)10100100
WithClientIP(...)10100100
WithPath(...)10100100
WithPath(...)10100100
WithPath(...)10100100
WithUrl(...)10100100
WithUrl(...)10100100
WithUrl(...)10100100
UsingDelete()10100100
UsingGet()10100100
UsingHead()10100100
UsingPost()10100100
UsingPatch()10100100
UsingPut()10100100
UsingAnyVerb()3063.64100
UsingVerb(...)10100100
WithBody(...)10100100
WithBody(...)10100100
WithBody(...)10100100
WithBody(...)10100100
WithBody(...)10100100
WithBody(...)10100100
WithBody(...)10100100
WithParam(...)1000
WithParam(...)10100100
WithParam(...)10100100
WithHeader(...)10100100
WithHeader(...)10100100
WithHeader(...)1000
WithHeader(...)1000
WithCookie(...)10100100
WithCookie(...)1000
WithCookie(...)1000

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Collections.ObjectModel;
 4using System.Linq;
 5using WireMock.Matchers;
 6using WireMock.Matchers.Request;
 7using WireMock.Util;
 8using WireMock.Validation;
 9
 10namespace WireMock.RequestBuilders
 11{
 12    /// <summary>
 13    /// The requests.
 14    /// </summary>
 15    public class Request : RequestMessageCompositeMatcher, IRequestBuilder
 16    {
 17        private readonly IList<IRequestMatcher> _requestMatchers;
 18
 19        /// <summary>
 20        /// Creates this instance.
 21        /// </summary>
 22        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 23        public static IRequestBuilder Create()
 15224        {
 15225            return new Request(new List<IRequestMatcher>());
 15226        }
 27
 28        /// <summary>
 29        /// Initializes a new instance of the <see cref="Request"/> class.
 30        /// </summary>
 31        /// <param name="requestMatchers">The request matchers.</param>
 15232        private Request(IList<IRequestMatcher> requestMatchers) : base(requestMatchers)
 15233        {
 15234            _requestMatchers = requestMatchers;
 15235        }
 36
 37        /// <summary>
 38        /// Gets the request message matchers.
 39        /// </summary>
 40        /// <typeparam name="T">Type of IRequestMatcher</typeparam>
 41        /// <returns>A List{T}</returns>
 42        public IList<T> GetRequestMessageMatchers<T>() where T : IRequestMatcher
 643        {
 644            return new ReadOnlyCollection<T>(_requestMatchers.Where(rm => rm is T).Cast<T>().ToList());
 645        }
 46
 47        /// <summary>
 48        /// Gets the request message matcher.
 49        /// </summary>
 50        /// <typeparam name="T">Type of IRequestMatcher</typeparam>
 51        /// <returns>A RequestMatcher</returns>
 52        public T GetRequestMessageMatcher<T>() where T : IRequestMatcher
 253        {
 254            return _requestMatchers.Where(rm => rm is T).Cast<T>().FirstOrDefault();
 255        }
 56
 57        /// <summary>
 58        /// The with clientIP.
 59        /// </summary>
 60        /// <param name="matchers">The matchers.</param>
 61        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 62        public IRequestBuilder WithClientIP(params IStringMatcher[] matchers)
 163        {
 164            Check.NotNullOrEmpty(matchers, nameof(matchers));
 65
 166            _requestMatchers.Add(new RequestMessageClientIPMatcher(matchers));
 167            return this;
 168        }
 69
 70        /// <summary>
 71        /// The with clientIP.
 72        /// </summary>
 73        /// <param name="clientIPs">The ClientIPs.</param>
 74        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 75        public IRequestBuilder WithClientIP(params string[] clientIPs)
 276        {
 277            Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
 78
 279            _requestMatchers.Add(new RequestMessageClientIPMatcher(clientIPs));
 280            return this;
 281        }
 82
 83        /// <summary>
 84        /// The with clientIP.
 85        /// </summary>
 86        /// <param name="funcs">The clientIP funcs.</param>
 87        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 88        public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
 189        {
 190            Check.NotNullOrEmpty(funcs, nameof(funcs));
 91
 192            _requestMatchers.Add(new RequestMessageClientIPMatcher(funcs));
 193            return this;
 194        }
 95
 96        /// <summary>
 97        /// The with path.
 98        /// </summary>
 99        /// <param name="matchers">The matchers.</param>
 100        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 101        public IRequestBuilder WithPath(params IStringMatcher[] matchers)
 21102        {
 21103            Check.NotNullOrEmpty(matchers, nameof(matchers));
 104
 21105            _requestMatchers.Add(new RequestMessagePathMatcher(matchers));
 21106            return this;
 21107        }
 108
 109        /// <summary>
 110        /// The with path.
 111        /// </summary>
 112        /// <param name="paths">The paths.</param>
 113        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 114        public IRequestBuilder WithPath(params string[] paths)
 98115        {
 98116            Check.NotNullOrEmpty(paths, nameof(paths));
 117
 98118            _requestMatchers.Add(new RequestMessagePathMatcher(paths));
 98119            return this;
 98120        }
 121
 122        /// <summary>
 123        /// The with path.
 124        /// </summary>
 125        /// <param name="funcs">The path func.</param>
 126        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 127        public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
 1128        {
 1129            Check.NotNullOrEmpty(funcs, nameof(funcs));
 130
 1131            _requestMatchers.Add(new RequestMessagePathMatcher(funcs));
 1132            return this;
 1133        }
 134
 135        /// <summary>
 136        /// The with url.
 137        /// </summary>
 138        /// <param name="matchers">The matchers.</param>
 139        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 140        public IRequestBuilder WithUrl(params IStringMatcher[] matchers)
 1141        {
 1142            Check.NotNullOrEmpty(matchers, nameof(matchers));
 143
 1144            _requestMatchers.Add(new RequestMessageUrlMatcher(matchers));
 1145            return this;
 1146        }
 147
 148        /// <summary>
 149        /// The with url.
 150        /// </summary>
 151        /// <param name="urls">The urls.</param>
 152        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 153        public IRequestBuilder WithUrl(params string[] urls)
 1154        {
 1155            Check.NotNullOrEmpty(urls, nameof(urls));
 156
 1157            _requestMatchers.Add(new RequestMessageUrlMatcher(urls));
 1158            return this;
 1159        }
 160
 161        /// <summary>
 162        /// The with url.
 163        /// </summary>
 164        /// <param name="funcs">The url func.</param>
 165        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 166        public IRequestBuilder WithUrl(params Func<string, bool>[] funcs)
 1167        {
 1168            Check.NotNullOrEmpty(funcs, nameof(funcs));
 169
 1170            _requestMatchers.Add(new RequestMessageUrlMatcher(funcs));
 1171            return this;
 1172        }
 173
 174        /// <inheritdoc cref="IMethodRequestBuilder.UsingDelete"/>
 175        public IRequestBuilder UsingDelete()
 16176        {
 16177            _requestMatchers.Add(new RequestMessageMethodMatcher("delete"));
 16178            return this;
 16179        }
 180
 181        /// <inheritdoc cref="IMethodRequestBuilder.UsingGet"/>
 182        public IRequestBuilder UsingGet()
 41183        {
 41184            _requestMatchers.Add(new RequestMessageMethodMatcher("get"));
 41185            return this;
 41186        }
 187
 188        /// <inheritdoc cref="IMethodRequestBuilder.UsingHead"/>
 189        public IRequestBuilder UsingHead()
 1190        {
 1191            _requestMatchers.Add(new RequestMessageMethodMatcher("head"));
 1192            return this;
 1193        }
 194
 195        /// <inheritdoc cref="IMethodRequestBuilder.UsingPost"/>
 196        public IRequestBuilder UsingPost()
 20197        {
 20198            _requestMatchers.Add(new RequestMessageMethodMatcher("post"));
 20199            return this;
 20200        }
 201
 202        /// <inheritdoc cref="IMethodRequestBuilder.UsingPatch"/>
 203        public IRequestBuilder UsingPatch()
 1204        {
 1205            _requestMatchers.Add(new RequestMessageMethodMatcher("patch"));
 1206            return this;
 1207        }
 208
 209        /// <inheritdoc cref="IMethodRequestBuilder.UsingPut"/>
 210        public IRequestBuilder UsingPut()
 6211        {
 6212            _requestMatchers.Add(new RequestMessageMethodMatcher("put"));
 6213            return this;
 6214        }
 215
 216        /// <inheritdoc cref="IMethodRequestBuilder.UsingAnyVerb"/>
 217        public IRequestBuilder UsingAnyVerb()
 24218        {
 28219            var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
 72220            foreach (var matcher in matchers)
 0221            {
 0222                _requestMatchers.Remove(matcher);
 0223            }
 224
 24225            return this;
 24226        }
 227
 228        /// <inheritdoc cref="IMethodRequestBuilder.UsingVerb"/>
 229        public IRequestBuilder UsingVerb(params string[] verbs)
 11230        {
 11231            Check.NotNullOrEmpty(verbs, nameof(verbs));
 232
 11233            _requestMatchers.Add(new RequestMessageMethodMatcher(verbs));
 11234            return this;
 11235        }
 236
 237        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(string)"/>
 238        public IRequestBuilder WithBody(string body)
 2239        {
 2240            _requestMatchers.Add(new RequestMessageBodyMatcher(body));
 2241            return this;
 2242        }
 243
 244        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(byte[])"/>
 245        public IRequestBuilder WithBody(byte[] body)
 1246        {
 1247            _requestMatchers.Add(new RequestMessageBodyMatcher(body));
 1248            return this;
 1249        }
 250
 251        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(object)"/>
 252        public IRequestBuilder WithBody(object body)
 1253        {
 1254            _requestMatchers.Add(new RequestMessageBodyMatcher(body));
 1255            return this;
 1256        }
 257
 258        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(IMatcher)"/>
 259        public IRequestBuilder WithBody(IMatcher matcher)
 13260        {
 13261            Check.NotNull(matcher, nameof(matcher));
 262
 13263            _requestMatchers.Add(new RequestMessageBodyMatcher(matcher));
 13264            return this;
 13265        }
 266
 267        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{string, bool})"/>
 268        public IRequestBuilder WithBody(Func<string, bool> func)
 1269        {
 1270            Check.NotNull(func, nameof(func));
 271
 1272            _requestMatchers.Add(new RequestMessageBodyMatcher(func));
 1273            return this;
 1274        }
 275
 276        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{byte[], bool})"/>
 277        public IRequestBuilder WithBody(Func<byte[], bool> func)
 1278        {
 1279            Check.NotNull(func, nameof(func));
 280
 1281            _requestMatchers.Add(new RequestMessageBodyMatcher(func));
 1282            return this;
 1283        }
 284
 285        /// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{object, bool})"/>
 286        public IRequestBuilder WithBody(Func<object, bool> func)
 1287        {
 1288            Check.NotNull(func, nameof(func));
 289
 1290            _requestMatchers.Add(new RequestMessageBodyMatcher(func));
 1291            return this;
 1292        }
 293
 294        /// <inheritdoc cref="IParamsRequestBuilder.WithParam(string)"/>
 295        public IRequestBuilder WithParam(string key)
 0296        {
 0297            Check.NotNull(key, nameof(key));
 298
 0299            _requestMatchers.Add(new RequestMessageParamMatcher(key));
 0300            return this;
 0301        }
 302
 303        /// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, string[])"/>
 304        public IRequestBuilder WithParam(string key, params string[] values)
 2305        {
 2306            Check.NotNull(key, nameof(key));
 307
 2308            _requestMatchers.Add(new RequestMessageParamMatcher(key, values));
 2309            return this;
 2310        }
 311
 312        /// <inheritdoc cref="IParamsRequestBuilder.WithParam(Func{IDictionary{string, WireMockList{string}}, bool}[])"/
 313        public IRequestBuilder WithParam(params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
 1314        {
 1315            Check.NotNullOrEmpty(funcs, nameof(funcs));
 316
 1317            _requestMatchers.Add(new RequestMessageParamMatcher(funcs));
 1318            return this;
 1319        }
 320
 321        /// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string,string,bool)"/>
 322        public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true)
 13323        {
 13324            Check.NotNull(name, nameof(name));
 13325            Check.NotNull(pattern, nameof(pattern));
 326
 13327            _requestMatchers.Add(new RequestMessageHeaderMatcher(name, pattern, ignoreCase));
 13328            return this;
 13329        }
 330
 331        /// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string,string[],bool)"/>
 332        public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true)
 12333        {
 12334            Check.NotNull(name, nameof(name));
 12335            Check.NotNull(patterns, nameof(patterns));
 336
 12337            _requestMatchers.Add(new RequestMessageHeaderMatcher(name, patterns, ignoreCase));
 12338            return this;
 12339        }
 340
 341        /// <summary>
 342        /// With header.
 343        /// </summary>
 344        /// <param name="name">The name.</param>
 345        /// <param name="matchers">The matchers.</param>
 346        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 347        public IRequestBuilder WithHeader(string name, params IStringMatcher[] matchers)
 0348        {
 0349            Check.NotNull(name, nameof(name));
 0350            Check.NotNullOrEmpty(matchers, nameof(matchers));
 351
 0352            _requestMatchers.Add(new RequestMessageHeaderMatcher(name, matchers));
 0353            return this;
 0354        }
 355
 356        /// <summary>
 357        /// With header.
 358        /// </summary>
 359        /// <param name="funcs">The funcs.</param>
 360        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 361        public IRequestBuilder WithHeader(params Func<IDictionary<string, string[]>, bool>[] funcs)
 0362        {
 0363            Check.NotNullOrEmpty(funcs, nameof(funcs));
 364
 0365            _requestMatchers.Add(new RequestMessageHeaderMatcher(funcs));
 0366            return this;
 0367        }
 368
 369        /// <summary>
 370        /// With cookie.
 371        /// </summary>
 372        /// <param name="name">The name.</param>
 373        /// <param name="pattern">The pattern.</param>
 374        /// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
 375        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 376        public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true)
 1377        {
 1378            _requestMatchers.Add(new RequestMessageCookieMatcher(name, pattern, ignoreCase));
 1379            return this;
 1380        }
 381
 382        /// <summary>
 383        /// With cookie.
 384        /// </summary>
 385        /// <param name="name">The name.</param>
 386        /// <param name="matchers">The matchers.</param>
 387        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 388        public IRequestBuilder WithCookie(string name, params IStringMatcher[] matchers)
 0389        {
 0390            Check.NotNullOrEmpty(matchers, nameof(matchers));
 391
 0392            _requestMatchers.Add(new RequestMessageCookieMatcher(name, matchers));
 0393            return this;
 0394        }
 395
 396        /// <summary>
 397        /// With header.
 398        /// </summary>
 399        /// <param name="funcs">The funcs.</param>
 400        /// <returns>The <see cref="IRequestBuilder"/>.</returns>
 401        public IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs)
 0402        {
 0403            Check.NotNullOrEmpty(funcs, nameof(funcs));
 404
 0405            _requestMatchers.Add(new RequestMessageCookieMatcher(funcs));
 0406            return this;
 0407        }
 408    }
 409}

Methods/Properties

Create()
.ctor(System.Collections.Generic.IList`1<WireMock.Matchers.Request.IRequestMatcher>)
GetRequestMessageMatchers()
GetRequestMessageMatcher()
WithClientIP(WireMock.Matchers.IStringMatcher[])
WithClientIP(System.String[])
WithClientIP(System.Func`2<System.String,System.Boolean>[])
WithPath(WireMock.Matchers.IStringMatcher[])
WithPath(System.String[])
WithPath(System.Func`2<System.String,System.Boolean>[])
WithUrl(WireMock.Matchers.IStringMatcher[])
WithUrl(System.String[])
WithUrl(System.Func`2<System.String,System.Boolean>[])
UsingDelete()
UsingGet()
UsingHead()
UsingPost()
UsingPatch()
UsingPut()
UsingAnyVerb()
UsingVerb(System.String[])
WithBody(System.String)
WithBody(System.Byte[])
WithBody(System.Object)
WithBody(WireMock.Matchers.IMatcher)
WithBody(System.Func`2<System.String,System.Boolean>)
WithBody(System.Func`2<System.Byte[],System.Boolean>)
WithBody(System.Func`2<System.Object,System.Boolean>)
WithParam(System.String)
WithParam(System.String,System.String[])
WithParam(System.Func`2<System.Collections.Generic.IDictionary`2<System.String,WireMock.Util.WireMockList`1<System.String>>,System.Boolean>[])
WithHeader(System.String,System.String,System.Boolean)
WithHeader(System.String,System.String[],System.Boolean)
WithHeader(System.String,WireMock.Matchers.IStringMatcher[])
WithHeader(System.Func`2<System.Collections.Generic.IDictionary`2<System.String,System.String[]>,System.Boolean>[])
WithCookie(System.String,System.String,System.Boolean)
WithCookie(System.String,WireMock.Matchers.IStringMatcher[])
WithCookie(System.Func`2<System.Collections.Generic.IDictionary`2<System.String,System.String>,System.Boolean>[])