Summary

Class:WireMock.Server.FluentMockServer
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs
C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.cs
Covered lines:256
Uncovered lines:445
Coverable lines:701
Total lines:1198
Line coverage:36.5%
Branch coverage:33.3%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
ReadStaticMappings(...)6484.6260
ReadStaticMapping(...)22100100
InitAdmin()1000
SettingsGet(...)3000
SettingsUpdate(...)3400
MappingGet(...)2200
MappingPut(...)4800
MappingDelete(...)2200
MappingsSave(...)6200
SanitizeFileName(...)1000
MappingsGet(...)4000
MappingsPost(...)1000
DeserializeAndAddMapping(...)106410069.23
MappingsDelete(...)1000
RequestGet(...)2200
RequestDelete(...)2200
RequestsGet(...)2000
ToLogEntryModel(...)7800
RequestsDelete(...)1000
RequestsFind(...)7200
InitRequestBuilder(...)271638439.6844.83
InitResponseBuilder(...)1251238.7136.84
ToMappingModel(...)416553600
Map(...)4200
Map(...)6800
Map(...)4200
Map(...)3200
Map(...)15102452.6347.62
ToJson(...)1000
ToEncoding(...)3210066.67
.ctor(...)155128057.89
.cctor()10100100
FindLogEntries(...)82100100
Start(...)1000
Start(...)10100100
Start(...)10100100
StartWithAdminInterface(...)1000
StartWithAdminInterface(...)1000
StartWithAdminInterfaceAndReadStaticMappings(...)1000
AddCatchAllMapping()2000
Stop()2210066.67
Dispose()3200
Reset()1000
ResetLogEntries()20100100
DeleteLogEntry(...)3200
ResetMappings()30100100
DeleteMapping(...)32100100
AddGlobalProcessingDelay(...)20100100
AllowPartialMapping()2000
SetBasicAuthentication(...)1000
Given(...)10100100
RegisterMapping(...)20100100
LogRequest(...)20100100
HandleRequestAsync()351638468.6366.67

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Text;
 6using JetBrains.Annotations;
 7using Newtonsoft.Json;
 8using SimMetrics.Net;
 9using WireMock.Admin.Mappings;
 10using WireMock.Admin.Requests;
 11using WireMock.Admin.Settings;
 12using WireMock.Logging;
 13using WireMock.Matchers;
 14using WireMock.Matchers.Request;
 15using WireMock.RequestBuilders;
 16using WireMock.ResponseBuilders;
 17using WireMock.Util;
 18using WireMock.Validation;
 19
 20namespace WireMock.Server
 21{
 22    /// <summary>
 23    /// The fluent mock server.
 24    /// </summary>
 25    public partial class FluentMockServer
 26    {
 127        private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings");
 28        private const string AdminMappings = "/__admin/mappings";
 29        private const string AdminRequests = "/__admin/requests";
 30        private const string AdminSettings = "/__admin/settings";
 1831        private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/mappings\/(\{{0,1}(
 1832        private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/requests\/(\{{0,1}(
 33
 1834        private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
 1835        {
 1836            Formatting = Formatting.Indented,
 1837            NullValueHandling = NullValueHandling.Ignore,
 1838        };
 39
 40        /// <summary>
 41        /// Reads the static mappings from a folder.
 42        /// </summary>
 43        /// <param name="folder">The optional folder. If not defined, use \__admin\mappings\</param>
 44        [PublicAPI]
 45        public void ReadStaticMappings([CanBeNull] string folder = null)
 146        {
 147             if (folder == null)
 048                folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
 49
 150             if (!Directory.Exists(folder))
 051                return;
 52
 953            foreach (string filename in Directory.EnumerateFiles(folder).OrderBy(f => f))
 254            {
 255                ReadStaticMapping(filename);
 256            }
 157        }
 58
 59        /// <summary>
 60        /// Reads the static mapping.
 61        /// </summary>
 62        /// <param name="filename">The filename.</param>
 63        [PublicAPI]
 64        public void ReadStaticMapping([NotNull] string filename)
 465        {
 466            Check.NotNull(filename, nameof(filename));
 67
 468            string filenameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
 69            Guid guidFromFilename;
 70
 471             if (Guid.TryParse(filenameWithoutExtension, out guidFromFilename))
 272            {
 273                DeserializeAndAddMapping(File.ReadAllText(filename), guidFromFilename);
 274            }
 75            else
 276            {
 277                DeserializeAndAddMapping(File.ReadAllText(filename));
 278            }
 479        }
 80
 81        private void InitAdmin()
 082        {
 83            // __admin/settings
 084            Given(Request.Create().WithPath(AdminSettings).UsingGet()).RespondWith(new DynamicResponseProvider(SettingsG
 085            Given(Request.Create().WithPath(AdminSettings).UsingVerb("PUT", "POST")).RespondWith(new DynamicResponseProv
 86
 87
 88            // __admin/mappings
 089            Given(Request.Create().WithPath(AdminMappings).UsingGet()).RespondWith(new DynamicResponseProvider(MappingsG
 090            Given(Request.Create().WithPath(AdminMappings).UsingPost()).RespondWith(new DynamicResponseProvider(Mappings
 091            Given(Request.Create().WithPath(AdminMappings).UsingDelete()).RespondWith(new DynamicResponseProvider(Mappin
 92
 93            // __admin/mappings/reset
 094            Given(Request.Create().WithPath(AdminMappings + "/reset").UsingPost()).RespondWith(new DynamicResponseProvid
 95
 96            // __admin/mappings/{guid}
 097            Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingGet()).RespondWith(new DynamicResponsePr
 098            Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingPut().WithHeader("Content-Type", "applic
 099            Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingDelete()).RespondWith(new DynamicRespons
 100
 101            // __admin/mappings/save
 0102            Given(Request.Create().WithPath(AdminMappings + "/save").UsingPost()).RespondWith(new DynamicResponseProvide
 103
 104
 105            // __admin/requests
 0106            Given(Request.Create().WithPath(AdminRequests).UsingGet()).RespondWith(new DynamicResponseProvider(RequestsG
 0107            Given(Request.Create().WithPath(AdminRequests).UsingDelete()).RespondWith(new DynamicResponseProvider(Reques
 108
 109            // __admin/requests/reset
 0110            Given(Request.Create().WithPath(AdminRequests + "/reset").UsingPost()).RespondWith(new DynamicResponseProvid
 111
 112            // __admin/request/{guid}
 0113            Given(Request.Create().WithPath(_adminRequestsGuidPathMatcher).UsingGet()).RespondWith(new DynamicResponsePr
 0114            Given(Request.Create().WithPath(_adminRequestsGuidPathMatcher).UsingDelete()).RespondWith(new DynamicRespons
 115
 116            // __admin/requests/find
 0117            Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).RespondWith(new DynamicResponseProvide
 0118        }
 119
 120        #region Settings
 121        private ResponseMessage SettingsGet(RequestMessage requestMessage)
 0122        {
 0123            var model = new SettingsModel
 0124            {
 0125                AllowPartialMapping = _allowPartialMapping,
 0126                GlobalProcessingDelay = _requestProcessingDelay?.Milliseconds
 0127            };
 128
 0129            return ToJson(model);
 0130        }
 131
 132        private ResponseMessage SettingsUpdate(RequestMessage requestMessage)
 0133        {
 0134            var settings = JsonConvert.DeserializeObject<SettingsModel>(requestMessage.Body);
 135
 0136             if (settings.AllowPartialMapping != null)
 0137                _allowPartialMapping = settings.AllowPartialMapping.Value;
 138
 0139             if (settings.GlobalProcessingDelay != null)
 0140                _requestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
 141
 0142            return new ResponseMessage { Body = "Settings updated" };
 0143        }
 144        #endregion Settings
 145
 146        #region Mapping/{guid}
 147        private ResponseMessage MappingGet(RequestMessage requestMessage)
 0148        {
 0149            Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));
 0150            var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);
 151
 0152             if (mapping == null)
 0153                return new ResponseMessage { StatusCode = 404, Body = "Mapping not found" };
 154
 0155            var model = ToMappingModel(mapping);
 156
 0157            return ToJson(model);
 0158        }
 159
 160        private ResponseMessage MappingPut(RequestMessage requestMessage)
 0161        {
 0162            Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));
 0163            var mappingModel = JsonConvert.DeserializeObject<MappingModel>(requestMessage.Body);
 164
 0165             if (mappingModel.Request == null)
 0166                return new ResponseMessage { StatusCode = 400, Body = "Request missing" };
 167
 0168             if (mappingModel.Response == null)
 0169                return new ResponseMessage { StatusCode = 400, Body = "Response missing" };
 170
 0171            var requestBuilder = InitRequestBuilder(mappingModel.Request);
 0172            var responseBuilder = InitResponseBuilder(mappingModel.Response);
 173
 0174            IRespondWithAProvider respondProvider = Given(requestBuilder).WithGuid(guid);
 175
 0176             if (!string.IsNullOrEmpty(mappingModel.Title))
 0177                respondProvider = respondProvider.WithTitle(mappingModel.Title);
 178
 0179            respondProvider.RespondWith(responseBuilder);
 180
 0181            return new ResponseMessage { Body = "Mapping added or updated" };
 0182        }
 183
 184        private ResponseMessage MappingDelete(RequestMessage requestMessage)
 0185        {
 0186            Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));
 187
 0188             if (DeleteMapping(guid))
 0189                return new ResponseMessage { Body = "Mapping removed" };
 190
 0191            return new ResponseMessage { Body = "Mapping not found" };
 0192        }
 193        #endregion Mapping/{guid}
 194
 195        #region Mappings
 196        private ResponseMessage MappingsSave(RequestMessage requestMessage)
 0197        {
 0198            string folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
 0199             if (!Directory.Exists(folder))
 0200                Directory.CreateDirectory(folder);
 201
 0202            foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))
 0203            {
 0204                var model = ToMappingModel(mapping);
 0205                string json = JsonConvert.SerializeObject(model, _settings);
 0206                string filename = !string.IsNullOrEmpty(mapping.Title) ? SanitizeFileName(mapping.Title) : mapping.Guid.
 207
 0208                File.WriteAllText(Path.Combine(folder, filename + ".json"), json);
 0209            }
 210
 0211            return new ResponseMessage { Body = "Mappings saved to disk" };
 0212        }
 213
 214        private static string SanitizeFileName(string name, char replaceChar = '_')
 0215        {
 0216            return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, replaceChar));
 0217        }
 218
 219        private ResponseMessage MappingsGet(RequestMessage requestMessage)
 0220        {
 0221            var result = new List<MappingModel>();
 0222            foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))
 0223            {
 0224                var model = ToMappingModel(mapping);
 0225                result.Add(model);
 0226            }
 227
 0228            return ToJson(result);
 0229        }
 230
 231        private ResponseMessage MappingsPost(RequestMessage requestMessage)
 0232        {
 233            try
 0234            {
 0235                DeserializeAndAddMapping(requestMessage.Body);
 0236            }
 0237            catch (ArgumentException a)
 0238            {
 0239                return new ResponseMessage { StatusCode = 400, Body = a.Message };
 240            }
 0241            catch (Exception e)
 0242            {
 0243                return new ResponseMessage { StatusCode = 500, Body = e.ToString() };
 244            }
 245
 0246            return new ResponseMessage { StatusCode = 201, Body = "Mapping added" };
 0247        }
 248
 249        private void DeserializeAndAddMapping(string json, Guid? guid = null)
 4250        {
 4251            var mappingModel = JsonConvert.DeserializeObject<MappingModel>(json);
 252
 4253            Check.NotNull(mappingModel, nameof(mappingModel));
 4254            Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
 4255            Check.NotNull(mappingModel.Response, nameof(mappingModel.Response));
 256
 4257            var requestBuilder = InitRequestBuilder(mappingModel.Request);
 4258            var responseBuilder = InitResponseBuilder(mappingModel.Response);
 259
 4260            IRespondWithAProvider respondProvider = Given(requestBuilder);
 261
 4262             if (guid != null)
 2263            {
 2264                respondProvider = respondProvider.WithGuid(guid.Value);
 2265            }
 2266             else if (mappingModel.Guid != null && mappingModel.Guid != Guid.Empty)
 2267            {
 2268                respondProvider = respondProvider.WithGuid(mappingModel.Guid.Value);
 2269            }
 270
 4271             if (!string.IsNullOrEmpty(mappingModel.Title))
 2272                respondProvider = respondProvider.WithTitle(mappingModel.Title);
 273
 4274             if (mappingModel.Priority != null)
 4275                respondProvider = respondProvider.AtPriority(mappingModel.Priority.Value);
 276
 4277            respondProvider.RespondWith(responseBuilder);
 4278        }
 279
 280        private ResponseMessage MappingsDelete(RequestMessage requestMessage)
 0281        {
 0282            ResetMappings();
 283
 0284            return new ResponseMessage { Body = "Mappings deleted" };
 0285        }
 286        #endregion Mappings
 287
 288        #region Request/{guid}
 289        private ResponseMessage RequestGet(RequestMessage requestMessage)
 0290        {
 0291            Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminRequests.Length + 1));
 0292            var entry = LogEntries.FirstOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid)
 293
 0294             if (entry == null)
 0295                return new ResponseMessage { StatusCode = 404, Body = "Request not found" };
 296
 0297            var model = ToLogEntryModel(entry);
 298
 0299            return ToJson(model);
 0300        }
 301
 302        private ResponseMessage RequestDelete(RequestMessage requestMessage)
 0303        {
 0304            Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminRequests.Length + 1));
 305
 0306             if (DeleteLogEntry(guid))
 0307                return new ResponseMessage { Body = "Request removed" };
 308
 0309            return new ResponseMessage { Body = "Request not found" };
 0310        }
 311        #endregion Request/{guid}
 312
 313        #region Requests
 314        private ResponseMessage RequestsGet(RequestMessage requestMessage)
 0315        {
 0316            var result = LogEntries
 0317                .Where(r => !r.RequestMessage.Path.StartsWith("/__admin/"))
 0318                .Select(ToLogEntryModel);
 319
 0320            return ToJson(result);
 0321        }
 322
 323        private LogEntryModel ToLogEntryModel(LogEntry logEntry)
 0324        {
 0325             return new LogEntryModel
 0326            {
 0327                Guid = logEntry.Guid,
 0328                Request = new LogRequestModel
 0329                {
 0330                    DateTime = logEntry.RequestMessage.DateTime,
 0331                    Path = logEntry.RequestMessage.Path,
 0332                    AbsoleteUrl = logEntry.RequestMessage.Url,
 0333                    Query = logEntry.RequestMessage.Query,
 0334                    Method = logEntry.RequestMessage.Method,
 0335                    Body = logEntry.RequestMessage.Body,
 0336                    Headers = logEntry.RequestMessage.Headers,
 0337                    Cookies = logEntry.RequestMessage.Cookies,
 0338                    BodyEncoding = logEntry.RequestMessage.BodyEncoding != null ? new EncodingModel
 0339                    {
 0340                        EncodingName = logEntry.RequestMessage.BodyEncoding.EncodingName,
 0341                        CodePage = logEntry.RequestMessage.BodyEncoding.CodePage,
 0342                        WebName = logEntry.RequestMessage.BodyEncoding.WebName
 0343                    } : null
 0344                },
 0345                Response = new LogResponseModel
 0346                {
 0347                    StatusCode = logEntry.ResponseMessage.StatusCode,
 0348                    Body = logEntry.ResponseMessage.Body,
 0349                    BodyOriginal = logEntry.ResponseMessage.BodyOriginal,
 0350                    Headers = logEntry.ResponseMessage.Headers,
 0351                    BodyEncoding = logEntry.ResponseMessage.BodyEncoding != null ? new EncodingModel
 0352                    {
 0353                        EncodingName = logEntry.ResponseMessage.BodyEncoding.EncodingName,
 0354                        CodePage = logEntry.ResponseMessage.BodyEncoding.CodePage,
 0355                        WebName = logEntry.ResponseMessage.BodyEncoding.WebName
 0356                    } : null
 0357                },
 0358                MappingGuid = logEntry.MappingGuid,
 0359                MappingTitle = logEntry.MappingTitle,
 0360                RequestMatchResult = logEntry.RequestMatchResult != null ? new LogRequestMatchModel
 0361                {
 0362                    TotalScore = logEntry.RequestMatchResult.TotalScore,
 0363                    TotalNumber = logEntry.RequestMatchResult.TotalNumber,
 0364                    IsPerfectMatch = logEntry.RequestMatchResult.IsPerfectMatch,
 0365                    AverageTotalScore = logEntry.RequestMatchResult.AverageTotalScore
 0366                } : null
 0367            };
 0368        }
 369
 370        private ResponseMessage RequestsDelete(RequestMessage requestMessage)
 0371        {
 0372            ResetLogEntries();
 373
 0374            return new ResponseMessage { Body = "Requests deleted" };
 0375        }
 376        #endregion Requests
 377
 378        #region Requests/find
 379        private ResponseMessage RequestsFind(RequestMessage requestMessage)
 0380        {
 0381            var requestModel = JsonConvert.DeserializeObject<RequestModel>(requestMessage.Body);
 382
 0383            var request = (Request)InitRequestBuilder(requestModel);
 384
 0385            var dict = new Dictionary<LogEntry, RequestMatchResult>();
 0386            foreach (var logEntry in LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/")))
 0387            {
 0388                var requestMatchResult = new RequestMatchResult();
 0389                 if (request.GetMatchingScore(logEntry.RequestMessage, requestMatchResult) > 0.99)
 0390                    dict.Add(logEntry, requestMatchResult);
 0391            }
 392
 0393            var result = dict.OrderBy(x => x.Value.AverageTotalScore).Select(x => x.Key);
 394
 0395            return ToJson(result);
 0396        }
 397        #endregion Requests/find
 398
 399        private IRequestBuilder InitRequestBuilder(RequestModel requestModel)
 4400        {
 4401            IRequestBuilder requestBuilder = Request.Create();
 402
 4403             if (requestModel.Path != null)
 4404            {
 4405                string path = requestModel.Path as string;
 4406                 if (path != null)
 0407                    requestBuilder = requestBuilder.WithPath(path);
 408                else
 4409                {
 4410                    var pathModel = JsonUtils.ParseJTokenToObject<PathModel>(requestModel.Path);
 4411                     if (pathModel?.Matchers != null)
 4412                        requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(Map).ToArray());
 4413                }
 4414            }
 415
 4416             if (requestModel.Url != null)
 0417            {
 0418                string url = requestModel.Url as string;
 0419                 if (url != null)
 0420                    requestBuilder = requestBuilder.WithUrl(url);
 421                else
 0422                {
 0423                    var urlModel = JsonUtils.ParseJTokenToObject<UrlModel>(requestModel.Url);
 0424                     if (urlModel?.Matchers != null)
 0425                        requestBuilder = requestBuilder.WithUrl(urlModel.Matchers.Select(Map).ToArray());
 0426                }
 0427            }
 428
 4429             if (requestModel.Methods != null)
 4430                requestBuilder = requestBuilder.UsingVerb(requestModel.Methods);
 431
 4432             if (requestModel.Headers != null)
 0433            {
 0434                foreach (var headerModel in requestModel.Headers.Where(h => h.Matchers != null))
 0435                {
 0436                    requestBuilder = requestBuilder.WithHeader(headerModel.Name, headerModel.Matchers.Select(Map).ToArra
 0437                }
 0438            }
 439
 4440             if (requestModel.Cookies != null)
 0441            {
 0442                foreach (var cookieModel in requestModel.Cookies.Where(c => c.Matchers != null))
 0443                {
 0444                    requestBuilder = requestBuilder.WithCookie(cookieModel.Name, cookieModel.Matchers.Select(Map).ToArra
 0445                }
 0446            }
 447
 4448             if (requestModel.Params != null)
 0449            {
 0450                foreach (var paramModel in requestModel.Params.Where(p => p.Values != null))
 0451                {
 0452                    requestBuilder = requestBuilder.WithParam(paramModel.Name, paramModel.Values.ToArray());
 0453                }
 0454            }
 455
 4456             if (requestModel.Body?.Matcher != null)
 2457            {
 2458                var bodyMatcher = Map(requestModel.Body.Matcher);
 2459                requestBuilder = requestBuilder.WithBody(bodyMatcher);
 2460            }
 461
 4462            return requestBuilder;
 4463        }
 464
 465        private IResponseBuilder InitResponseBuilder(ResponseModel responseModel)
 4466        {
 4467            IResponseBuilder responseBuilder = Response.Create();
 468
 4469             if (responseModel.StatusCode.HasValue)
 4470                responseBuilder = responseBuilder.WithStatusCode(responseModel.StatusCode.Value);
 471
 4472             if (responseModel.Headers != null)
 4473                responseBuilder = responseBuilder.WithHeaders(responseModel.Headers);
 0474             else if (responseModel.HeadersRaw != null)
 0475            {
 0476                foreach (string headerLine in responseModel.HeadersRaw.Split(new[] { "\n", "\r\n" }, StringSplitOptions.
 0477                {
 0478                    int indexColon = headerLine.IndexOf(":", StringComparison.Ordinal);
 0479                    string key = headerLine.Substring(0, indexColon).TrimStart(' ', '\t');
 0480                    string value = headerLine.Substring(indexColon + 1).TrimStart(' ', '\t');
 0481                    responseBuilder = responseBuilder.WithHeader(key, value);
 0482                }
 0483            }
 484
 4485             if (responseModel.Body != null)
 4486                responseBuilder = responseBuilder.WithBody(responseModel.Body, ToEncoding(responseModel.BodyEncoding));
 0487             else if (responseModel.BodyAsJson != null)
 0488                responseBuilder = responseBuilder.WithBodyAsJson(responseModel.BodyAsJson, ToEncoding(responseModel.Body
 0489             else if (responseModel.BodyAsBase64 != null)
 0490                responseBuilder = responseBuilder.WithBodyAsBase64(responseModel.BodyAsBase64, ToEncoding(responseModel.
 491
 4492             if (responseModel.UseTransformer)
 0493                responseBuilder = responseBuilder.WithTransformer();
 494
 4495             if (responseModel.Delay > 0)
 0496                responseBuilder = responseBuilder.WithDelay(responseModel.Delay.Value);
 497
 4498            return responseBuilder;
 4499        }
 500
 501        private MappingModel ToMappingModel(Mapping mapping)
 0502        {
 0503            var request = (Request)mapping.RequestMatcher;
 0504            var response = (Response)mapping.Provider;
 505
 0506            var pathMatchers = request.GetRequestMessageMatchers<RequestMessagePathMatcher>();
 0507            var urlMatchers = request.GetRequestMessageMatchers<RequestMessageUrlMatcher>();
 0508            var headerMatchers = request.GetRequestMessageMatchers<RequestMessageHeaderMatcher>();
 0509            var cookieMatchers = request.GetRequestMessageMatchers<RequestMessageCookieMatcher>();
 0510            var paramsMatchers = request.GetRequestMessageMatchers<RequestMessageParamMatcher>();
 0511            var bodyMatcher = request.GetRequestMessageMatcher<RequestMessageBodyMatcher>();
 0512            var methodMatcher = request.GetRequestMessageMatcher<RequestMessageMethodMatcher>();
 513
 0514             return new MappingModel
 0515            {
 0516                Guid = mapping.Guid,
 0517                Title = mapping.Title,
 0518                Priority = mapping.Priority,
 0519                Request = new RequestModel
 0520                {
 0521                    Path = pathMatchers != null && pathMatchers.Any() ? new PathModel
 0522                    {
 0523                        Matchers = Map(pathMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)),
 0524                        Funcs = Map(pathMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
 0525                    } : null,
 0526
 0527                    Url = urlMatchers != null && urlMatchers.Any() ? new UrlModel
 0528                    {
 0529                        Matchers = Map(urlMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)),
 0530                        Funcs = Map(urlMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
 0531                    } : null,
 0532
 0533                    Methods = methodMatcher?.Methods,
 0534
 0535                    Headers = headerMatchers != null && headerMatchers.Any() ? headerMatchers.Select(hm => new HeaderMod
 0536                    {
 0537                        Name = hm.Name,
 0538                        Matchers = Map(hm.Matchers),
 0539                        Funcs = Map(hm.Funcs)
 0540                    }).ToList() : null,
 0541
 0542                    Cookies = cookieMatchers != null && cookieMatchers.Any() ? cookieMatchers.Select(cm => new CookieMod
 0543                    {
 0544                        Name = cm.Name,
 0545                        Matchers = Map(cm.Matchers),
 0546                        Funcs = Map(cm.Funcs)
 0547                    }).ToList() : null,
 0548
 0549                     Params = paramsMatchers != null && paramsMatchers.Any() ? paramsMatchers.Select(pm => new ParamModel
 0550                    {
 0551                        Name = pm.Key,
 0552                        Values = pm.Values?.ToList(),
 0553                        Funcs = Map(pm.Funcs)
 0554                    }).ToList() : null,
 0555
 0556                    Body = methodMatcher?.Methods != null && methodMatcher.Methods.Count(m => m == "get") == 1 ? null : 
 0557                    {
 0558                        Matcher = bodyMatcher != null ? Map(bodyMatcher.Matcher) : null,
 0559                        Func = bodyMatcher != null ? Map(bodyMatcher.Func) : null,
 0560                        DataFunc = bodyMatcher != null ? Map(bodyMatcher.DataFunc) : null
 0561                    }
 0562                },
 0563                Response = new ResponseModel
 0564                {
 0565                    StatusCode = response.ResponseMessage.StatusCode,
 0566                    Headers = response.ResponseMessage.Headers,
 0567                    Body = response.ResponseMessage.Body,
 0568                    UseTransformer = response.UseTransformer,
 0569                    Delay = response.Delay?.Milliseconds,
 0570
 0571                    BodyEncoding = response.ResponseMessage.BodyEncoding != null ? new EncodingModel
 0572                    {
 0573                        EncodingName = response.ResponseMessage.BodyEncoding.EncodingName,
 0574                        CodePage = response.ResponseMessage.BodyEncoding.CodePage,
 0575                        WebName = response.ResponseMessage.BodyEncoding.WebName
 0576                    } : null
 0577                }
 0578            };
 0579        }
 580
 581        private MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers)
 0582        {
 0583             if (matchers == null || !matchers.Any())
 0584                return null;
 585
 0586            return matchers.Select(Map).Where(x => x != null).ToArray();
 0587        }
 588
 589        private MatcherModel Map([CanBeNull] IMatcher matcher)
 0590        {
 0591             if (matcher == null)
 0592                return null;
 593
 0594            var patterns = matcher.GetPatterns();
 595
 0596             return new MatcherModel
 0597            {
 0598                Name = matcher.GetName(),
 0599                Pattern = patterns.Length == 1 ? patterns.First() : null,
 0600                Patterns = patterns.Length > 1 ? patterns : null
 0601            };
 0602        }
 603
 604        private string[] Map<T>([CanBeNull] IEnumerable<Func<T, bool>> funcs)
 0605        {
 0606             if (funcs == null || !funcs.Any())
 0607                return null;
 608
 0609            return funcs.Select(Map).Where(x => x != null).ToArray();
 0610        }
 611
 612        private string Map<T>([CanBeNull] Func<T, bool> func)
 0613        {
 0614             return func?.ToString();
 0615        }
 616
 617        private IMatcher Map([CanBeNull] MatcherModel matcher)
 6618        {
 6619             if (matcher == null)
 0620                return null;
 621
 6622            var parts = matcher.Name.Split('.');
 6623            string matcherName = parts[0];
 6624             string matcherType = parts.Length > 1 ? parts[1] : null;
 625
 6626            string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
 627
 6628             switch (matcherName)
 629            {
 630                case "ExactMatcher":
 4631                    return new ExactMatcher(patterns);
 632
 633                case "RegexMatcher":
 0634                    return new RegexMatcher(patterns);
 635
 636                case "JsonPathMatcher":
 0637                    return new JsonPathMatcher(patterns);
 638
 639                case "XPathMatcher":
 0640                    return new XPathMatcher(matcher.Pattern);
 641
 642                case "WildcardMatcher":
 2643                     return new WildcardMatcher(patterns, matcher.IgnoreCase == true);
 644
 645                case "SimMetricsMatcher":
 0646                    SimMetricType type = SimMetricType.Levenstein;
 0647                     if (!string.IsNullOrEmpty(matcherType) && !Enum.TryParse(matcherType, out type))
 0648                        throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not suppo
 649
 0650                    return new SimMetricsMatcher(matcher.Pattern, type);
 651
 652                default:
 0653                    throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
 654            }
 6655        }
 656
 657        private ResponseMessage ToJson<T>(T result)
 0658        {
 0659            return new ResponseMessage
 0660            {
 0661                Body = JsonConvert.SerializeObject(result, _settings),
 0662                StatusCode = 200,
 0663                Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
 0664            };
 0665        }
 666
 667        private Encoding ToEncoding(EncodingModel encodingModel)
 4668        {
 4669             return encodingModel != null ? Encoding.GetEncoding(encodingModel.CodePage) : null;
 4670        }
 671    }
 672}

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Collections.ObjectModel;
 5using System.Linq;
 6using System.Net;
 7using System.Text;
 8using System.Threading.Tasks;
 9using JetBrains.Annotations;
 10using WireMock.Http;
 11using WireMock.Logging;
 12using WireMock.Matchers;
 13using WireMock.Matchers.Request;
 14using WireMock.RequestBuilders;
 15using WireMock.Validation;
 16using System.Threading;
 17
 18namespace WireMock.Server
 19{
 20    /// <summary>
 21    /// The fluent mock server.
 22    /// </summary>
 23    public partial class FluentMockServer : IDisposable
 24    {
 25        private readonly TinyHttpServer _httpServer;
 26
 1827        private IList<Mapping> _mappings = new List<Mapping>();
 28
 1829        private readonly IList<LogEntry> _logEntries = new List<LogEntry>();
 30
 1831        private readonly HttpListenerRequestMapper _requestMapper = new HttpListenerRequestMapper();
 32
 1833        private readonly HttpListenerResponseMapper _responseMapper = new HttpListenerResponseMapper();
 34
 1835        private readonly object _syncRoot = new object();
 36
 37        private TimeSpan? _requestProcessingDelay;
 38
 39        private bool _allowPartialMapping;
 40
 41        private IMatcher _authorizationMatcher;
 42
 43        /// <summary>
 44        /// Gets the ports.
 45        /// </summary>
 46        /// <value>
 47        /// The ports.
 48        /// </value>
 49        [PublicAPI]
 1350        public List<int> Ports { get; }
 51
 52        /// <summary>
 53        /// Gets the urls.
 54        /// </summary>
 55        [PublicAPI]
 1856        public string[] Urls { get; }
 57
 58        /// <summary>
 59        /// Gets the request logs.
 60        /// </summary>
 61        [PublicAPI]
 62        public IEnumerable<LogEntry> LogEntries
 63        {
 64            get
 365            {
 366                lock (((ICollection)_logEntries).SyncRoot)
 367                {
 368                    return new ReadOnlyCollection<LogEntry>(_logEntries);
 69                }
 370            }
 71        }
 72
 73        /// <summary>
 74        /// The search log-entries based on matchers.
 75        /// </summary>
 76        /// <param name="matchers">The matchers.</param>
 77        /// <returns>The <see cref="IEnumerable"/>.</returns>
 78        [PublicAPI]
 79        public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
 180        {
 181            lock (((ICollection)_logEntries).SyncRoot)
 182            {
 183                var results = new Dictionary<LogEntry, RequestMatchResult>();
 84
 785                foreach (var log in _logEntries)
 286                {
 287                    var requestMatchResult = new RequestMatchResult();
 1088                    foreach (var matcher in matchers)
 289                    {
 290                        matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
 291                    }
 92
 293                     if (requestMatchResult.AverageTotalScore > 0.99)
 194                        results.Add(log, requestMatchResult);
 295                }
 96
 397                return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
 98            }
 199        }
 100
 101        /// <summary>
 102        /// Gets the mappings.
 103        /// </summary>
 104        [PublicAPI]
 105        public IEnumerable<Mapping> Mappings
 106        {
 107            get
 7108            {
 7109                lock (((ICollection)_mappings).SyncRoot)
 7110                {
 7111                    return new ReadOnlyCollection<Mapping>(_mappings);
 112                }
 7113            }
 114        }
 115
 116        /// <summary>
 117        /// Starts the specified settings.
 118        /// </summary>
 119        /// <param name="settings">The FluentMockServerSettings.</param>
 120        /// <returns>The <see cref="FluentMockServer"/>.</returns>
 121        [PublicAPI]
 122        public static FluentMockServer Start(FluentMockServerSettings settings)
 0123        {
 0124            Check.NotNull(settings, nameof(settings));
 125
 0126            return new FluentMockServer(settings);
 0127        }
 128
 129        /// <summary>
 130        /// Start this FluentMockServer.
 131        /// </summary>
 132        /// <param name="port">The port.</param>
 133        /// <param name="ssl">The SSL support.</param>
 134        /// <returns>The <see cref="FluentMockServer"/>.</returns>
 135        [PublicAPI]
 136        public static FluentMockServer Start([CanBeNull] int? port = 0, bool ssl = false)
 16137        {
 16138            return new FluentMockServer(new FluentMockServerSettings
 16139            {
 16140                Port = port,
 16141                UseSSL = ssl
 16142            });
 16143        }
 144
 145        /// <summary>
 146        /// Start this FluentMockServer.
 147        /// </summary>
 148        /// <param name="urls">The urls to listen on.</param>
 149        /// <returns>The <see cref="FluentMockServer"/>.</returns>
 150        [PublicAPI]
 151        public static FluentMockServer Start(params string[] urls)
 2152        {
 2153            Check.NotEmpty(urls, nameof(urls));
 154
 2155            return new FluentMockServer(new FluentMockServerSettings
 2156            {
 2157                Urls = urls
 2158            });
 2159        }
 160
 161        /// <summary>
 162        /// Start this FluentMockServer with the admin interface.
 163        /// </summary>
 164        /// <param name="port">The port.</param>
 165        /// <param name="ssl">The SSL support.</param>
 166        /// <returns>The <see cref="FluentMockServer"/>.</returns>
 167        [PublicAPI]
 168        public static FluentMockServer StartWithAdminInterface(int? port = 0, bool ssl = false)
 0169        {
 0170            return new FluentMockServer(new FluentMockServerSettings
 0171            {
 0172                Port = port,
 0173                UseSSL = ssl,
 0174                StartAdminInterface = true
 0175            });
 0176        }
 177
 178        /// <summary>
 179        /// Start this FluentMockServer with the admin interface.
 180        /// </summary>
 181        /// <param name="urls">The urls.</param>
 182        /// <returns>The <see cref="FluentMockServer"/>.</returns>
 183        [PublicAPI]
 184        public static FluentMockServer StartWithAdminInterface(params string[] urls)
 0185        {
 0186            Check.NotEmpty(urls, nameof(urls));
 187
 0188            return new FluentMockServer(new FluentMockServerSettings
 0189            {
 0190                Urls = urls,
 0191                StartAdminInterface = true
 0192            });
 0193        }
 194
 195        /// <summary>
 196        /// Start this FluentMockServer with the admin interface and read static mappings.
 197        /// </summary>
 198        /// <param name="urls">The urls.</param>
 199        /// <returns>The <see cref="FluentMockServer"/>.</returns>
 200        [PublicAPI]
 201        public static FluentMockServer StartWithAdminInterfaceAndReadStaticMappings(params string[] urls)
 0202        {
 0203            Check.NotEmpty(urls, nameof(urls));
 204
 0205            return new FluentMockServer(new FluentMockServerSettings
 0206            {
 0207                Urls = urls,
 0208                StartAdminInterface = true,
 0209                ReadStaticMappings = true
 0210            });
 0211        }
 212
 18213        private FluentMockServer(FluentMockServerSettings settings)
 18214        {
 18215             if (settings.Urls != null)
 2216            {
 2217                Urls = settings.Urls;
 2218            }
 219            else
 16220            {
 16221                 int port = settings.Port > 0 ? settings.Port.Value : PortUtil.FindFreeTcpPort();
 16222                 Urls = new[] { (settings.UseSSL == true ? "https" : "http") + "://localhost:" + port + "/" };
 16223            }
 224
 18225            _httpServer = new TinyHttpServer(HandleRequestAsync, Urls);
 18226            Ports = _httpServer.Ports;
 227
 18228            _httpServer.Start();
 229
 18230             if (settings.StartAdminInterface == true)
 0231            {
 0232                InitAdmin();
 0233            }
 234
 18235             if (settings.ReadStaticMappings == true)
 0236            {
 0237                ReadStaticMappings();
 0238            }
 18239        }
 240
 241        /// <summary>
 242        /// Adds the catch all mapping.
 243        /// </summary>
 244        [PublicAPI]
 245        public void AddCatchAllMapping()
 0246        {
 0247            Given(Request.Create().WithPath("/*").UsingAnyVerb())
 0248                .WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
 0249                .AtPriority(1000)
 0250                .RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No m
 0251        }
 252
 253        /// <summary>
 254        /// Stop this server.
 255        /// </summary>
 256        [PublicAPI]
 257        public void Stop()
 18258        {
 18259             _httpServer?.Stop();
 18260        }
 261
 262        /// <summary>
 263        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 264        /// </summary>
 265        public void Dispose()
 0266        {
 0267             if (_httpServer != null && _httpServer.IsStarted)
 0268            {
 0269                _httpServer.Stop();
 0270            }
 0271        }
 272
 273        /// <summary>
 274        /// Resets LogEntries and Mappings.
 275        /// </summary>
 276        [PublicAPI]
 277        public void Reset()
 0278        {
 0279            ResetLogEntries();
 280
 0281            ResetMappings();
 0282        }
 283
 284        /// <summary>
 285        /// Resets the LogEntries.
 286        /// </summary>
 287        [PublicAPI]
 288        public void ResetLogEntries()
 1289        {
 1290            lock (((ICollection)_logEntries).SyncRoot)
 1291            {
 1292                _logEntries.Clear();
 1293            }
 1294        }
 295
 296        /// <summary>
 297        /// Deletes the mapping.
 298        /// </summary>
 299        /// <param name="guid">The unique identifier.</param>
 300        [PublicAPI]
 301        public bool DeleteLogEntry(Guid guid)
 0302        {
 0303            lock (((ICollection)_logEntries).SyncRoot)
 0304            {
 305                // Check a logentry exists with the same GUID, if so, remove it.
 0306                var existing = _logEntries.FirstOrDefault(m => m.Guid == guid);
 0307                 if (existing != null)
 0308                {
 0309                    _logEntries.Remove(existing);
 0310                    return true;
 311                }
 312
 0313                return false;
 314            }
 0315        }
 316
 317        /// <summary>
 318        /// Resets the Mappings.
 319        /// </summary>
 320        [PublicAPI]
 321        public void ResetMappings()
 1322        {
 1323            lock (((ICollection)_mappings).SyncRoot)
 1324            {
 2325                _mappings = _mappings.Where(m => m.Provider is DynamicResponseProvider).ToList();
 1326            }
 1327        }
 328
 329        /// <summary>
 330        /// Deletes the mapping.
 331        /// </summary>
 332        /// <param name="guid">The unique identifier.</param>
 333        [PublicAPI]
 334        public bool DeleteMapping(Guid guid)
 17335        {
 17336            lock (((ICollection)_mappings).SyncRoot)
 17337            {
 338                // Check a mapping exists with the same GUID, if so, remove it.
 22339                var existingMapping = _mappings.FirstOrDefault(m => m.Guid == guid);
 17340                 if (existingMapping != null)
 1341                {
 1342                    _mappings.Remove(existingMapping);
 1343                    return true;
 344                }
 345
 16346                return false;
 347            }
 17348        }
 349
 350        /// <summary>
 351        /// The add request processing delay.
 352        /// </summary>
 353        /// <param name="delay">
 354        /// The delay.
 355        /// </param>
 356        [PublicAPI]
 357        public void AddGlobalProcessingDelay(TimeSpan delay)
 1358        {
 1359            lock (_syncRoot)
 1360            {
 1361                _requestProcessingDelay = delay;
 1362            }
 1363        }
 364
 365        /// <summary>
 366        /// Allows the partial mapping.
 367        /// </summary>
 368        [PublicAPI]
 369        public void AllowPartialMapping()
 0370        {
 0371            lock (_syncRoot)
 0372            {
 0373                _allowPartialMapping = true;
 0374            }
 0375        }
 376
 377        /// <summary>
 378        /// Sets the basic authentication.
 379        /// </summary>
 380        /// <param name="username">The username.</param>
 381        /// <param name="password">The password.</param>
 382        [PublicAPI]
 383        public void SetBasicAuthentication([NotNull] string username, [NotNull] string password)
 0384        {
 0385            Check.NotNull(username, nameof(username));
 0386            Check.NotNull(password, nameof(password));
 387
 0388            string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + p
 0389            _authorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$");
 0390        }
 391
 392        /// <summary>
 393        /// The given.
 394        /// </summary>
 395        /// <param name="requestMatcher">The request matcher.</param>
 396        /// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
 397        [PublicAPI]
 398        public IRespondWithAProvider Given(IRequestMatcher requestMatcher)
 17399        {
 17400            return new RespondWithAProvider(RegisterMapping, requestMatcher);
 17401        }
 402
 403        /// <summary>
 404        /// The register mapping.
 405        /// </summary>
 406        /// <param name="mapping">
 407        /// The mapping.
 408        /// </param>
 409        private void RegisterMapping(Mapping mapping)
 17410        {
 17411            lock (((ICollection)_mappings).SyncRoot)
 17412            {
 413                // Check a mapping exists with the same GUID, if so, remove it first.
 17414                DeleteMapping(mapping.Guid);
 415
 17416                _mappings.Add(mapping);
 17417            }
 17418        }
 419
 420        /// <summary>
 421        /// The log request.
 422        /// </summary>
 423        /// <param name="entry">The request.</param>
 424        private void LogRequest(LogEntry entry)
 13425        {
 13426            lock (((ICollection)_logEntries).SyncRoot)
 13427            {
 13428                _logEntries.Add(entry);
 13429            }
 13430        }
 431
 432        /// <summary>
 433        /// The handle request.
 434        /// </summary>
 435        /// <param name="ctx">The HttpListenerContext.</param>
 436        /// <param name="cancel">The CancellationToken.</param>
 437        private async void HandleRequestAsync(HttpListenerContext ctx, CancellationToken cancel)
 13438        {
 13439             if (cancel.IsCancellationRequested)
 0440                return;
 441
 13442             if (_requestProcessingDelay > TimeSpan.Zero)
 1443            {
 1444                lock (_syncRoot)
 1445                {
 1446                    Task.Delay(_requestProcessingDelay.Value, cancel).Wait(cancel);
 1447                }
 1448            }
 449
 13450            var request = _requestMapper.Map(ctx.Request);
 451
 13452            ResponseMessage response = null;
 13453            Mapping targetMapping = null;
 13454             RequestMatchResult requestMatchResult = null;
 455            try
 13456            {
 13457                var mappings = _mappings
 23458                    .Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) })
 13459                    .ToList();
 460
 13461                 if (_allowPartialMapping)
 0462                {
 0463                    var partialMappings = mappings
 0464                        .Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdmin
 0465                        .OrderBy(m => m.MatchResult)
 0466                        .ThenBy(m => m.Mapping.Priority)
 0467                        .ToList();
 468
 0469                    var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0);
 470
 0471                     targetMapping = bestPartialMatch?.Mapping;
 0472                     requestMatchResult = bestPartialMatch?.MatchResult;
 0473                }
 474                else
 13475                {
 13476                    var perfectMatch = mappings
 23477                        .OrderBy(m => m.Mapping.Priority)
 21478                        .FirstOrDefault(m => m.MatchResult.IsPerfectMatch);
 479
 13480                     targetMapping = perfectMatch?.Mapping;
 13481                     requestMatchResult = perfectMatch?.MatchResult;
 13482                }
 483
 13484                 if (targetMapping == null)
 6485                {
 6486                    response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" };
 6487                    return;
 488                }
 489
 7490                 if (targetMapping.IsAdminInterface && _authorizationMatcher != null)
 0491                {
 492                    string authorization;
 0493                    bool present = request.Headers.TryGetValue("Authorization", out authorization);
 0494                     if (!present || _authorizationMatcher.IsMatch(authorization) < 1.0)
 0495                    {
 0496                        response = new ResponseMessage { StatusCode = 401 };
 0497                        return;
 498                    }
 0499                }
 500
 7501                response = await targetMapping.ResponseTo(request);
 7502            }
 0503            catch (Exception ex)
 0504            {
 0505                response = new ResponseMessage { StatusCode = 500, Body = ex.ToString() };
 0506             }
 507            finally
 13508            {
 13509                 var log = new LogEntry
 13510                {
 13511                    Guid = Guid.NewGuid(),
 13512                    RequestMessage = request,
 13513                    ResponseMessage = response,
 13514                    MappingGuid = targetMapping?.Guid,
 13515                    MappingTitle = targetMapping?.Title,
 13516                    RequestMatchResult = requestMatchResult
 13517                };
 518
 13519                LogRequest(log);
 520
 13521                _responseMapper.Map(response, ctx.Response);
 13522                ctx.Response.Close();
 13523            }
 13524        }
 525    }
 526}

Methods/Properties

.cctor()
.ctor(WireMock.Server.FluentMockServerSettings)
ReadStaticMappings(System.String)
ReadStaticMapping(System.String)
InitAdmin()
SettingsGet(WireMock.RequestMessage)
SettingsUpdate(WireMock.RequestMessage)
MappingGet(WireMock.RequestMessage)
MappingPut(WireMock.RequestMessage)
MappingDelete(WireMock.RequestMessage)
MappingsSave(WireMock.RequestMessage)
SanitizeFileName(System.String,System.Char)
MappingsGet(WireMock.RequestMessage)
MappingsPost(WireMock.RequestMessage)
DeserializeAndAddMapping(System.String,System.Nullable`1<System.Guid>)
MappingsDelete(WireMock.RequestMessage)
RequestGet(WireMock.RequestMessage)
RequestDelete(WireMock.RequestMessage)
RequestsGet(WireMock.RequestMessage)
ToLogEntryModel(WireMock.Logging.LogEntry)
RequestsDelete(WireMock.RequestMessage)
RequestsFind(WireMock.RequestMessage)
InitRequestBuilder(WireMock.Admin.Mappings.RequestModel)
InitResponseBuilder(WireMock.Admin.Mappings.ResponseModel)
ToMappingModel(WireMock.Mapping)
Map(System.Collections.Generic.IEnumerable`1<WireMock.Matchers.IMatcher>)
Map(WireMock.Matchers.IMatcher)
Map(System.Collections.Generic.IEnumerable`1<System.Func`2<T,System.Boolean>>)
Map(System.Func`2<T,System.Boolean>)
Map(WireMock.Admin.Mappings.MatcherModel)
ToJson(T)
ToEncoding(WireMock.Admin.Mappings.EncodingModel)
Ports()
Urls()
LogEntries()
FindLogEntries(WireMock.Matchers.Request.IRequestMatcher[])
Mappings()
Start(WireMock.Server.FluentMockServerSettings)
Start(System.Nullable`1<System.Int32>,System.Boolean)
Start(System.String[])
StartWithAdminInterface(System.Nullable`1<System.Int32>,System.Boolean)
StartWithAdminInterface(System.String[])
StartWithAdminInterfaceAndReadStaticMappings(System.String[])
AddCatchAllMapping()
Stop()
Dispose()
Reset()
ResetLogEntries()
DeleteLogEntry(System.Guid)
ResetMappings()
DeleteMapping(System.Guid)
AddGlobalProcessingDelay(System.TimeSpan)
AllowPartialMapping()
SetBasicAuthentication(System.String,System.String)
Given(WireMock.Matchers.Request.IRequestMatcher)
RegisterMapping(WireMock.Mapping)
LogRequest(WireMock.Logging.LogEntry)
HandleRequestAsync()