# Summary

Class: | WireMock.Server.FluentMockServer
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.cs C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.LogEntries.cs
Covered lines: | 399
Uncovered lines: | 333
Coverable lines: | 732
Total lines: | 1311
Line coverage: | 54.5%
Branch coverage: | 58%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
InitAdmin() | 0 | 0 | 1 | 0
SaveStaticMappings(...) | 0 | 0 | 1 | 1
ReadStaticMappings(...) | 0 | 0 | 0.81 | 1
WatchStaticMappings(...) | 0 | 0 | 0.25 | 0.75
ReadStaticMappingAndAddOrUpdate(...) | 0 | 0 | 1 | 1
InitProxyAndRecord(...) | 0 | 0 | 1 | 1
ToMapping(...) | 0 | 0 | 0 | 0
SettingsGet(...) | 0 | 0 | 1 | 0.5
SettingsUpdate(...) | 0 | 0 | 0.571 | 0.5
MappingGet(...) | 0 | 0 | 0 | 0
MappingPut(...) | 0 | 0 | 0 | 0
MappingDelete(...) | 0 | 0 | 0 | 0
MappingsSave(...) | 0 | 0 | 0 | 0
SaveMappingToFile(...) | 0 | 0 | 0.8 | 0.667
SanitizeFileName(...) | 0 | 0 | 0 | 0
MappingsGet(...) | 0 | 0 | 0 | 0
MappingsPost(...) | 0 | 0 | 0.467 | 0
DeserializeAndAddOrUpdateMapping(...) | 0 | 0 | 0.821 | 0.8
MappingsDelete(...) | 0 | 0 | 0 | 0
RequestGet(...) | 0 | 0 | 0 | 0
RequestDelete(...) | 0 | 0 | 0 | 0
RequestsGet(...) | 0 | 0 | 1 | 1
RequestsDelete(...) | 0 | 0 | 0 | 0
RequestsFind(...) | 0 | 0 | 1 | 1
ScenariosGet(...) | 0 | 0 | 0 | 0
ScenariosReset(...) | 0 | 0 | 0 | 0
InitRequestBuilder(...) | 0 | 0 | 0.424 | 0.404
InitResponseBuilder(...) | 0 | 0 | 0.574 | 0.618
ToJson(...) | 0 | 0 | 1 | 0.5
ToEncoding(...) | 0 | 0 | 1 | 1
DeserializeObject(...) | 0 | 0 | 1 | 0.5
.ctor(...) | 0 | 0 | 1 | 0
ProxyAndRecordAsync() | 0 | 0 | 0 | 0
Dispose() | 0 | 0 | 0 | 0
Dispose(...) | 0 | 0 | 0 | 0
Start(...) | 0 | 0 | 1 | 0
Start(...) | 0 | 0 | 1 | 0
Start(...) | 0 | 0 | 1 | 0
StartWithAdminInterface(...) | 0 | 0 | 1 | 0
StartWithAdminInterface(...) | 0 | 0 | 0 | 0
StartWithAdminInterfaceAndReadStaticMappings(...) | 0 | 0 | 0 | 0
Stop() | 0 | 0 | 1 | 0.75
AddCatchAllMapping() | 0 | 0 | 0 | 0
Reset() | 0 | 0 | 0 | 0
ResetMappings() | 0 | 0 | 1 | 1
DeleteMapping(...) | 0 | 0 | 0 | 0
DeleteMapping(...) | 0 | 0 | 0 | 0
AddGlobalProcessingDelay(...) | 0 | 0 | 1 | 0
AllowPartialMapping(...) | 0 | 0 | 0 | 0
SetBasicAuthentication(...) | 0 | 0 | 1 | 0
RemoveBasicAuthentication() | 0 | 0 | 1 | 0
SetMaxRequestLogCount(...) | 0 | 0 | 1 | 0
SetRequestLogExpirationDuration(...) | 0 | 0 | 0 | 0
ResetScenarios() | 0 | 0 | 0 | 0
Given(...) | 0 | 0 | 1 | 0
RegisterMapping(...) | 0 | 0 | 1 | 1
.ctor(...) | 0 | 0 | 0.75 | 0.659
add_LogEntriesChanged(...) | 0 | 0 | 1 | 0
remove_LogEntriesChanged(...) | 0 | 0 | 0 | 0
FindLogEntries(...) | 0 | 0 | 1 | 1
ResetLogEntries() | 0 | 0 | 1 | 0
DeleteLogEntry(...) | 0 | 0 | 0 | 0

# File(s)

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.Admin.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Collections.Generic;`
|  | `3` |  | `using System.IO;`
|  | `4` |  | `using System.Linq;`
|  | `5` |  | `using System.Net.Http;`
|  | `6` |  | `using System.Text;`
|  | `7` |  | `using System.Threading.Tasks;`
|  | `8` |  | `using JetBrains.Annotations;`
|  | `9` |  | `using Newtonsoft.Json;`
|  | `10` |  | `using Newtonsoft.Json.Linq;`
|  | `11` |  | `using WireMock.Admin.Mappings;`
|  | `12` |  | `using WireMock.Admin.Scenarios;`
|  | `13` |  | `using WireMock.Admin.Settings;`
|  | `14` |  | `using WireMock.Http;`
|  | `15` |  | `using WireMock.Logging;`
|  | `16` |  | `using WireMock.Matchers;`
|  | `17` |  | `using WireMock.Matchers.Request;`
|  | `18` |  | `using WireMock.RequestBuilders;`
|  | `19` |  | `using WireMock.ResponseBuilders;`
|  | `20` |  | `using WireMock.ResponseProviders;`
|  | `21` |  | `using WireMock.Serialization;`
|  | `22` |  | `using WireMock.Settings;`
|  | `23` |  | `using WireMock.Util;`
|  | `24` |  | `using WireMock.Validation;`
|  | `25` |  | ``
|  | `26` |  | `namespace WireMock.Server`
|  | `27` |  | `{`
|  | `28` |  | `/// <summary>`
|  | `29` |  | `/// The fluent mock server.`
|  | `30` |  | `/// </summary>`
|  | `31` |  | `public partial class FluentMockServer`
|  | `32` |  | `{`
|  | `33` |  | `private const int EnhancedFileSystemWatcherTimeoutMs = 1000;`
|  | `34` |  | `private const int AdminPriority = int.MinValue;`
|  | `35` |  | `private const int ProxyPriority = 1000;`
|  | `36` |  | `private const string ContentTypeJson = "application/json";`
|  | `37` |  | `private const string AdminMappings = "/__admin/mappings";`
|  | `38` |  | `private const string AdminRequests = "/__admin/requests";`
|  | `39` |  | `private const string AdminSettings = "/__admin/settings";`
|  | `40` |  | `private const string AdminScenarios = "/__admin/scenarios";`
|  | `41` |  | ``
| 55 | `42` |  | `private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^`
| 55 | `43` |  | `private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^`
|  | `44` |  | ``
| 55 | `45` |  | `private readonly JsonSerializerSettings _settings = new JsonSerializerSettings`
| 55 | `46` |  | `{`
| 55 | `47` |  | `Formatting = Formatting.Indented,`
| 55 | `48` |  | `NullValueHandling = NullValueHandling.Ignore`
| 55 | `49` |  | `};`
|  | `50` |  | ``
| 55 | `51` |  | `private readonly JsonSerializerSettings _settingsIncludeNullValues = new JsonSerializerSettings`
| 55 | `52` |  | `{`
| 55 | `53` |  | `Formatting = Formatting.Indented,`
| 55 | `54` |  | `NullValueHandling = NullValueHandling.Include`
| 55 | `55` |  | `};`
|  | `56` |  | ``
|  | `57` |  | `#region InitAdmin`
|  | `58` |  | `private void InitAdmin()`
| 11 | `59` |  | `{`
|  | `60` |  | `// __admin/settings`
| 11 | `61` |  | `Given(Request.Create().WithPath(AdminSettings).UsingGet()).AtPriority(AdminPriority).RespondWith(new Dynamic`
| 11 | `62` |  | `Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.Co`
|  | `63` |  | ``
|  | `64` |  | `// __admin/mappings`
| 11 | `65` |  | `Given(Request.Create().WithPath(AdminMappings).UsingGet()).AtPriority(AdminPriority).RespondWith(new Dynamic`
| 11 | `66` |  | `Given(Request.Create().WithPath(AdminMappings).UsingPost().WithHeader(HttpKnownHeaderNames.ContentType, Cont`
| 11 | `67` |  | `Given(Request.Create().WithPath(AdminMappings).UsingDelete()).AtPriority(AdminPriority).RespondWith(new Dyna`
|  | `68` |  | ``
|  | `69` |  | `// __admin/mappings/reset`
| 11 | `70` |  | `Given(Request.Create().WithPath(AdminMappings + "/reset").UsingPost()).AtPriority(AdminPriority).RespondWith`
|  | `71` |  | ``
|  | `72` |  | `// __admin/mappings/{guid}`
| 11 | `73` |  | `Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingGet()).AtPriority(AdminPriority).Respond`
| 11 | `74` |  | `Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingPut().WithHeader(HttpKnownHeaderNames.Co`
| 11 | `75` |  | `Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingDelete()).AtPriority(AdminPriority).Resp`
|  | `76` |  | ``
|  | `77` |  | `// __admin/mappings/save`
| 11 | `78` |  | `Given(Request.Create().WithPath(AdminMappings + "/save").UsingPost()).AtPriority(AdminPriority).RespondWith(`
|  | `79` |  | ``
|  | `80` |  | `// __admin/requests`
| 11 | `81` |  | `Given(Request.Create().WithPath(AdminRequests).UsingGet()).AtPriority(AdminPriority).RespondWith(new Dynamic`
| 11 | `82` |  | `Given(Request.Create().WithPath(AdminRequests).UsingDelete()).AtPriority(AdminPriority).RespondWith(new Dyna`
|  | `83` |  | ``
|  | `84` |  | `// __admin/requests/reset`
| 11 | `85` |  | `Given(Request.Create().WithPath(AdminRequests + "/reset").UsingPost()).AtPriority(AdminPriority).RespondWith`
|  | `86` |  | ``
|  | `87` |  | `// __admin/request/{guid}`
| 11 | `88` |  | `Given(Request.Create().WithPath(_adminRequestsGuidPathMatcher).UsingGet()).AtPriority(AdminPriority).Respond`
| 11 | `89` |  | `Given(Request.Create().WithPath(_adminRequestsGuidPathMatcher).UsingDelete()).AtPriority(AdminPriority).Resp`
|  | `90` |  | ``
|  | `91` |  | `// __admin/requests/find`
| 11 | `92` |  | `Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).AtPriority(AdminPriority).RespondWith(`
|  | `93` |  | ``
|  | `94` |  | `// __admin/scenarios`
| 11 | `95` |  | `Given(Request.Create().WithPath(AdminScenarios).UsingGet()).AtPriority(AdminPriority).RespondWith(new Dynami`
| 11 | `96` |  | `Given(Request.Create().WithPath(AdminScenarios).UsingDelete()).AtPriority(AdminPriority).RespondWith(new Dyn`
|  | `97` |  | ``
|  | `98` |  | `// __admin/scenarios/reset`
| 11 | `99` |  | `Given(Request.Create().WithPath(AdminScenarios + "/reset").UsingPost()).AtPriority(AdminPriority).RespondWit`
| 11 | `100` |  | `}`
|  | `101` |  | `#endregion`
|  | `102` |  | ``
|  | `103` |  | `#region StaticMappings`
|  | `104` |  | `/// <summary>`
|  | `105` |  | `/// Saves the static mappings.`
|  | `106` |  | `/// </summary>`
|  | `107` |  | `/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>`
|  | `108` |  | `[PublicAPI]`
|  | `109` |  | `public void SaveStaticMappings([CanBeNull] string folder = null)`
| 1 | `110` |  | `{`
| 6 | `111` |  | `foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))`
| 1 | `112` |  | `{`
| 1 | `113` |  | `SaveMappingToFile(mapping, folder);`
| 1 | `114` |  | `}`
| 1 | `115` |  | `}`
|  | `116` |  | ``
|  | `117` |  | `/// <summary>`
|  | `118` |  | `/// Reads the static mappings from a folder.`
|  | `119` |  | `/// </summary>`
|  | `120` |  | `/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>`
|  | `121` |  | `[PublicAPI]`
|  | `122` |  | `public void ReadStaticMappings([CanBeNull] string folder = null)`
| 4 | `123` |  | `{`
| 4 | `124` |  | `if (folder == null)`
| 1 | `125` |  | `{`
| 1 | `126` |  | `folder = _fileSystemHandler.GetMappingFolder();`
| 1 | `127` |  | `}`
|  | `128` |  | ``
| 4 | `129` |  | `if (!_fileSystemHandler.FolderExists(folder))`
| 1 | `130` |  | `{`
| 1 | `131` |  | `_logger.Info("The Static Mapping folder '{0}' does not exist, reading Static MappingFiles will be skippe`
| 1 | `132` |  | `return;`
|  | `133` |  | `}`
|  | `134` |  | ``
| 27 | `135` |  | `foreach (string filename in _fileSystemHandler.EnumerateFiles(folder).OrderBy(f => f))`
| 6 | `136` |  | `{`
| 6 | `137` |  | `_logger.Info("Reading Static MappingFile : '{0}'", filename);`
|  | `138` |  | ``
|  | `139` |  | `try`
| 6 | `140` |  | `{`
| 6 | `141` |  | `ReadStaticMappingAndAddOrUpdate(filename);`
| 6 | `142` |  | `}`
| 0 | `143` |  | `catch`
| 0 | `144` |  | `{`
| 0 | `145` |  | `_logger.Error("Static MappingFile : '{0}' could not be read. This file will be skipped.", filename);`
| 0 | `146` |  | `}`
| 6 | `147` |  | `}`
| 4 | `148` |  | `}`
|  | `149` |  | ``
|  | `150` |  | `/// <summary>`
|  | `151` |  | `/// Watches the static mappings for changes.`
|  | `152` |  | `/// </summary>`
|  | `153` |  | `/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>`
|  | `154` |  | `[PublicAPI]`
|  | `155` |  | `public void WatchStaticMappings([CanBeNull] string folder = null)`
| 1 | `156` |  | `{`
| 1 | `157` |  | `if (folder == null)`
| 1 | `158` |  | `{`
| 1 | `159` |  | `folder = _fileSystemHandler.GetMappingFolder();`
| 1 | `160` |  | `}`
|  | `161` |  | ``
| 1 | `162` |  | `if (!_fileSystemHandler.FolderExists(folder))`
| 1 | `163` |  | `{`
| 1 | `164` |  | `return;`
|  | `165` |  | `}`
|  | `166` |  | ``
| 0 | `167` |  | `_logger.Info("Watching folder '{0}' for new, updated and deleted MappingFiles.", folder);`
|  | `168` |  | ``
| 0 | `169` |  | `var watcher = new EnhancedFileSystemWatcher(folder, "*.json", EnhancedFileSystemWatcherTimeoutMs);`
| 0 | `170` |  | `watcher.Created += (sender, args) =>`
| 0 | `171` |  | `{`
| 0 | `172` |  | `_logger.Info("New MappingFile created : '{0}'", args.FullPath);`
| 0 | `173` |  | `ReadStaticMappingAndAddOrUpdate(args.FullPath);`
| 0 | `174` |  | `};`
| 0 | `175` |  | `watcher.Changed += (sender, args) =>`
| 0 | `176` |  | `{`
| 0 | `177` |  | `_logger.Info("New MappingFile updated : '{0}'", args.FullPath);`
| 0 | `178` |  | `ReadStaticMappingAndAddOrUpdate(args.FullPath);`
| 0 | `179` |  | `};`
| 0 | `180` |  | `watcher.Deleted += (sender, args) =>`
| 0 | `181` |  | `{`
| 0 | `182` |  | `_logger.Info("New MappingFile deleted : '{0}'", args.FullPath);`
| 0 | `183` |  | `string filenameWithoutExtension = Path.GetFileNameWithoutExtension(args.FullPath);`
| 0 | `184` |  | ``
| 0 | `185` |  | `if (Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))`
| 0 | `186` |  | `{`
| 0 | `187` |  | `DeleteMapping(guidFromFilename);`
| 0 | `188` |  | `}`
| 0 | `189` |  | `else`
| 0 | `190` |  | `{`
| 0 | `191` |  | `DeleteMapping(args.FullPath);`
| 0 | `192` |  | `}`
| 0 | `193` |  | `};`
|  | `194` |  | ``
| 0 | `195` |  | `watcher.EnableRaisingEvents = true;`
| 1 | `196` |  | `}`
|  | `197` |  | ``
|  | `198` |  | `/// <summary>`
|  | `199` |  | `/// Reads a static mapping file and adds or updates the mapping.`
|  | `200` |  | `/// </summary>`
|  | `201` |  | `/// <param name="path">The path.</param>`
|  | `202` |  | `[PublicAPI]`
|  | `203` |  | `public void ReadStaticMappingAndAddOrUpdate([NotNull] string path)`
| 10 | `204` |  | `{`
| 10 | `205` |  | `Check.NotNull(path, nameof(path));`
|  | `206` |  | ``
| 10 | `207` |  | `string filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);`
|  | `208` |  | ``
| 10 | `209` |  | `MappingModel mappingModel = JsonConvert.DeserializeObject<MappingModel>(_fileSystemHandler.ReadMappingFile(p`
| 10 | `210` |  | `if (Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))`
| 6 | `211` |  | `{`
| 6 | `212` |  | `DeserializeAndAddOrUpdateMapping(mappingModel, guidFromFilename, path);`
| 6 | `213` |  | `}`
|  | `214` |  | `else`
| 4 | `215` |  | `{`
| 4 | `216` |  | `DeserializeAndAddOrUpdateMapping(mappingModel, null, path);`
| 4 | `217` |  | `}`
| 10 | `218` |  | `}`
|  | `219` |  | `#endregion`
|  | `220` |  | ``
|  | `221` |  | `#region Proxy and Record`
|  | `222` |  | `private HttpClient _httpClientForProxy;`
|  | `223` |  | ``
|  | `224` |  | `private void InitProxyAndRecord(IFluentMockServerSettings settings)`
| 2 | `225` |  | `{`
| 2 | `226` |  | `_httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ProxyAndRecordSettings.ClientX509Certificat`
|  | `227` |  | ``
| 2 | `228` |  | `var respondProvider = Given(Request.Create().WithPath("/*").UsingAnyMethod());`
| 2 | `229` |  | `if (settings.StartAdminInterface == true)`
| 1 | `230` |  | `{`
| 1 | `231` |  | `respondProvider.AtPriority(ProxyPriority);`
| 1 | `232` |  | `}`
|  | `233` |  | ``
| 2 | `234` |  | `respondProvider.RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings.ProxyAndRecordSetti`
| 2 | `235` |  | `}`
|  | `236` |  | ``
|  | `237` |  | `private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, IProxyAndRecordSettings s`
| 0 | `238` |  | `{`
| 0 | `239` |  | `var requestUri = new Uri(requestMessage.Url);`
| 0 | `240` |  | `var proxyUri = new Uri(settings.Url);`
| 0 | `241` |  | `var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery);`
|  | `242` |  | ``
| 0 | `243` |  | `var responseMessage = await HttpClientHelper.SendAsync(_httpClientForProxy, requestMessage, proxyUriWithRequ`
|  | `244` |  | ``
| 0 | `245` |  | `if (settings.SaveMapping)`
| 0 | `246` |  | `{`
| 0 | `247` |  | `var mapping = ToMapping(requestMessage, responseMessage, settings.BlackListedHeaders ?? new string[] { }`
| 0 | `248` |  | `_options.Mappings.TryAdd(mapping.Guid, mapping);`
|  | `249` |  | ``
| 0 | `250` |  | `if (settings.SaveMappingToFile)`
| 0 | `251` |  | `{`
| 0 | `252` |  | `SaveMappingToFile(mapping);`
| 0 | `253` |  | `}`
| 0 | `254` |  | `}`
|  | `255` |  | ``
| 0 | `256` |  | `return responseMessage;`
| 0 | `257` |  | `}`
|  | `258` |  | ``
|  | `259` |  | `private Mapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] blacklistedHe`
| 0 | `260` |  | `{`
| 0 | `261` |  | `var request = Request.Create();`
| 0 | `262` |  | `request.WithPath(requestMessage.Path);`
| 0 | `263` |  | `request.UsingMethod(requestMessage.Method);`
|  | `264` |  | ``
| 0 | `265` |  | `requestMessage.Query.Loop((key, value) => request.WithParam(key, value.ToArray()));`
| 0 | `266` |  | `requestMessage.Cookies.Loop((key, value) => request.WithCookie(key, value));`
|  | `267` |  | ``
| 0 | `268` |  | `var allBlackListedHeaders = new List<string>(blacklistedHeaders) { "Cookie" };`
| 0 | `269` |  | `requestMessage.Headers.Loop((key, value) =>`
| 0 | `270` |  | `{`
| 0 | `271` |  | `if (!allBlackListedHeaders.Any(b => string.Equals(key, b, StringComparison.OrdinalIgnoreCase)))`
| 0 | `272` |  | `{`
| 0 | `273` |  | `request.WithHeader(key, value.ToArray());`
| 0 | `274` |  | `}`
| 0 | `275` |  | `});`
|  | `276` |  | ``
| 0 | `277` |  | `if (requestMessage.BodyAsJson != null)`
| 0 | `278` |  | `{`
| 0 | `279` |  | `request.WithBody(new JsonMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyAsJson));`
| 0 | `280` |  | `}`
| 0 | `281` |  | `else if (requestMessage.Body != null)`
| 0 | `282` |  | `{`
| 0 | `283` |  | `request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.Body));`
| 0 | `284` |  | `}`
|  | `285` |  | ``
| 0 | `286` |  | `var response = Response.Create(responseMessage);`
|  | `287` |  | ``
| 0 | `288` |  | `return new Mapping(Guid.NewGuid(), string.Empty, null, request, response, 0, null, null, null);`
| 0 | `289` |  | `}`
|  | `290` |  | `#endregion`
|  | `291` |  | ``
|  | `292` |  | `#region Settings`
|  | `293` |  | `private ResponseMessage SettingsGet(RequestMessage requestMessage)`
| 1 | `294` |  | `{`
| 1 | `295` |  | `var model = new SettingsModel`
| 1 | `296` |  | `{`
| 1 | `297` |  | `AllowPartialMapping = _options.AllowPartialMapping,`
| 1 | `298` |  | `MaxRequestLogCount = _options.MaxRequestLogCount,`
| 1 | `299` |  | `RequestLogExpirationDuration = _options.RequestLogExpirationDuration,`
| 1 | `300` |  | `GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds`
| 1 | `301` |  | `};`
|  | `302` |  | ``
| 1 | `303` |  | `return ToJson(model);`
| 1 | `304` |  | `}`
|  | `305` |  | ``
|  | `306` |  | `private ResponseMessage SettingsUpdate(RequestMessage requestMessage)`
| 2 | `307` |  | `{`
| 2 | `308` |  | `var settings = DeserializeObject<SettingsModel>(requestMessage);`
| 2 | `309` |  | `_options.MaxRequestLogCount = settings.MaxRequestLogCount;`
| 2 | `310` |  | `_options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;`
|  | `311` |  | ``
| 2 | `312` |  | `if (settings.AllowPartialMapping != null)`
| 0 | `313` |  | `{`
| 0 | `314` |  | `_options.AllowPartialMapping = settings.AllowPartialMapping.Value;`
| 0 | `315` |  | `}`
|  | `316` |  | ``
| 2 | `317` |  | `if (settings.GlobalProcessingDelay != null)`
| 0 | `318` |  | `{`
| 0 | `319` |  | `_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);`
| 0 | `320` |  | `}`
|  | `321` |  | ``
| 2 | `322` |  | `return ResponseMessageBuilder.Create("Settings updated");`
| 2 | `323` |  | `}`
|  | `324` |  | `#endregion Settings`
|  | `325` |  | ``
|  | `326` |  | `#region Mapping/{guid}`
|  | `327` |  | `private ResponseMessage MappingGet(RequestMessage requestMessage)`
| 0 | `328` |  | `{`
| 0 | `329` |  | `Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));`
| 0 | `330` |  | `var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);`
|  | `331` |  | ``
| 0 | `332` |  | `if (mapping == null)`
| 0 | `333` |  | `{`
| 0 | `334` |  | `_logger.Warn("HttpStatusCode set to 404 : Mapping not found");`
| 0 | `335` |  | `return ResponseMessageBuilder.Create("Mapping not found", 404);`
|  | `336` |  | `}`
|  | `337` |  | ``
| 0 | `338` |  | `var model = MappingConverter.ToMappingModel(mapping);`
|  | `339` |  | ``
| 0 | `340` |  | `return ToJson(model);`
| 0 | `341` |  | `}`
|  | `342` |  | ``
|  | `343` |  | `private ResponseMessage MappingPut(RequestMessage requestMessage)`
| 0 | `344` |  | `{`
| 0 | `345` |  | `Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));`
|  | `346` |  | ``
| 0 | `347` |  | `var mappingModel = DeserializeObject<MappingModel>(requestMessage);`
| 0 | `348` |  | `Guid? guidFromPut = DeserializeAndAddOrUpdateMapping(mappingModel, guid);`
|  | `349` |  | ``
| 0 | `350` |  | `return ResponseMessageBuilder.Create("Mapping added or updated", 200, guidFromPut);`
| 0 | `351` |  | `}`
|  | `352` |  | ``
|  | `353` |  | `private ResponseMessage MappingDelete(RequestMessage requestMessage)`
| 0 | `354` |  | `{`
| 0 | `355` |  | `Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));`
|  | `356` |  | ``
| 0 | `357` |  | `if (DeleteMapping(guid))`
| 0 | `358` |  | `{`
| 0 | `359` |  | `return ResponseMessageBuilder.Create("Mapping removed", 200, guid);`
|  | `360` |  | `}`
|  | `361` |  | ``
| 0 | `362` |  | `return ResponseMessageBuilder.Create("Mapping not found", 404);`
| 0 | `363` |  | `}`
|  | `364` |  | `#endregion Mapping/{guid}`
|  | `365` |  | ``
|  | `366` |  | `#region Mappings`
|  | `367` |  | `private ResponseMessage MappingsSave(RequestMessage requestMessage)`
| 0 | `368` |  | `{`
| 0 | `369` |  | `SaveStaticMappings();`
|  | `370` |  | ``
| 0 | `371` |  | `return ResponseMessageBuilder.Create("Mappings saved to disk");`
| 0 | `372` |  | `}`
|  | `373` |  | ``
|  | `374` |  | `private void SaveMappingToFile(Mapping mapping, string folder = null)`
| 1 | `375` |  | `{`
| 1 | `376` |  | `if (folder == null)`
| 1 | `377` |  | `{`
| 1 | `378` |  | `folder = _fileSystemHandler.GetMappingFolder();`
| 1 | `379` |  | `}`
|  | `380` |  | ``
| 1 | `381` |  | `if (!_fileSystemHandler.FolderExists(folder))`
| 0 | `382` |  | `{`
| 0 | `383` |  | `_fileSystemHandler.CreateFolder(folder);`
| 0 | `384` |  | `}`
|  | `385` |  | ``
| 1 | `386` |  | `var model = MappingConverter.ToMappingModel(mapping);`
| 1 | `387` |  | `string filename = (!string.IsNullOrEmpty(mapping.Title) ? SanitizeFileName(mapping.Title) : mapping.Guid.ToS`
|  | `388` |  | ``
| 1 | `389` |  | `string path = Path.Combine(folder, filename);`
|  | `390` |  | ``
| 1 | `391` |  | `_logger.Info("Saving Mapping file {0}", filename);`
|  | `392` |  | ``
| 1 | `393` |  | `_fileSystemHandler.WriteMappingFile(path, JsonConvert.SerializeObject(model, _settings));`
| 1 | `394` |  | `}`
|  | `395` |  | ``
|  | `396` |  | `private static string SanitizeFileName(string name, char replaceChar = '_')`
| 0 | `397` |  | `{`
| 0 | `398` |  | `return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, replaceChar));`
| 0 | `399` |  | `}`
|  | `400` |  | ``
|  | `401` |  | `private ResponseMessage MappingsGet(RequestMessage requestMessage)`
| 0 | `402` |  | `{`
| 0 | `403` |  | `var result = new List<MappingModel>();`
| 0 | `404` |  | `foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))`
| 0 | `405` |  | `{`
| 0 | `406` |  | `var model = MappingConverter.ToMappingModel(mapping);`
| 0 | `407` |  | `result.Add(model);`
| 0 | `408` |  | `}`
|  | `409` |  | ``
| 0 | `410` |  | `return ToJson(result);`
| 0 | `411` |  | `}`
|  | `412` |  | ``
|  | `413` |  | `private ResponseMessage MappingsPost(RequestMessage requestMessage)`
| 1 | `414` |  | `{`
|  | `415` |  | `Guid? guid;`
|  | `416` |  | `try`
| 1 | `417` |  | `{`
| 1 | `418` |  | `var mappingModel = DeserializeObject<MappingModel>(requestMessage);`
| 1 | `419` |  | `guid = DeserializeAndAddOrUpdateMapping(mappingModel);`
| 1 | `420` |  | `}`
| 0 | `421` |  | `catch (ArgumentException a)`
| 0 | `422` |  | `{`
| 0 | `423` |  | `_logger.Error("HttpStatusCode set to 400 {0}", a);`
| 0 | `424` |  | `return ResponseMessageBuilder.Create(a.Message, 400);`
|  | `425` |  | `}`
| 0 | `426` |  | `catch (Exception e)`
| 0 | `427` |  | `{`
| 0 | `428` |  | `_logger.Error("HttpStatusCode set to 500 {0}", e);`
| 0 | `429` |  | `return ResponseMessageBuilder.Create(e.ToString(), 500);`
|  | `430` |  | `}`
|  | `431` |  | ``
| 1 | `432` |  | `return ResponseMessageBuilder.Create("Mapping added", 201, guid);`
| 1 | `433` |  | `}`
|  | `434` |  | ``
|  | `435` |  | `private Guid? DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)`
| 11 | `436` |  | `{`
| 11 | `437` |  | `Check.NotNull(mappingModel, nameof(mappingModel));`
| 11 | `438` |  | `Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));`
| 11 | `439` |  | `Check.NotNull(mappingModel.Response, nameof(mappingModel.Response));`
|  | `440` |  | ``
| 11 | `441` |  | `var requestBuilder = InitRequestBuilder(mappingModel.Request, true);`
| 11 | `442` |  | `if (requestBuilder == null)`
| 0 | `443` |  | `{`
| 0 | `444` |  | `return null;`
|  | `445` |  | `}`
|  | `446` |  | ``
| 11 | `447` |  | `var responseBuilder = InitResponseBuilder(mappingModel.Response);`
|  | `448` |  | ``
| 11 | `449` |  | `var respondProvider = Given(requestBuilder);`
|  | `450` |  | ``
| 11 | `451` |  | `if (guid != null)`
| 6 | `452` |  | `{`
| 6 | `453` |  | `respondProvider = respondProvider.WithGuid(guid.Value);`
| 6 | `454` |  | `}`
| 5 | `455` |  | `else if (mappingModel.Guid != null && mappingModel.Guid != Guid.Empty)`
| 3 | `456` |  | `{`
| 3 | `457` |  | `respondProvider = respondProvider.WithGuid(mappingModel.Guid.Value);`
| 3 | `458` |  | `}`
|  | `459` |  | ``
| 11 | `460` |  | `if (path != null)`
| 10 | `461` |  | `{`
| 10 | `462` |  | `respondProvider = respondProvider.WithPath(path);`
| 10 | `463` |  | `}`
|  | `464` |  | ``
| 11 | `465` |  | `if (!string.IsNullOrEmpty(mappingModel.Title))`
| 4 | `466` |  | `{`
| 4 | `467` |  | `respondProvider = respondProvider.WithTitle(mappingModel.Title);`
| 4 | `468` |  | `}`
|  | `469` |  | ``
| 11 | `470` |  | `if (mappingModel.Priority != null)`
| 10 | `471` |  | `{`
| 10 | `472` |  | `respondProvider = respondProvider.AtPriority(mappingModel.Priority.Value);`
| 10 | `473` |  | `}`
|  | `474` |  | ``
| 11 | `475` |  | `if (mappingModel.Scenario != null)`
| 0 | `476` |  | `{`
| 0 | `477` |  | `respondProvider = respondProvider.InScenario(mappingModel.Scenario);`
| 0 | `478` |  | `respondProvider = respondProvider.WhenStateIs(mappingModel.WhenStateIs);`
| 0 | `479` |  | `respondProvider = respondProvider.WillSetStateTo(mappingModel.SetStateTo);`
| 0 | `480` |  | `}`
|  | `481` |  | ``
| 11 | `482` |  | `respondProvider.RespondWith(responseBuilder);`
|  | `483` |  | ``
| 11 | `484` |  | `return respondProvider.Guid;`
| 11 | `485` |  | `}`
|  | `486` |  | ``
|  | `487` |  | `private ResponseMessage MappingsDelete(RequestMessage requestMessage)`
| 0 | `488` |  | `{`
| 0 | `489` |  | `ResetMappings();`
|  | `490` |  | ``
| 0 | `491` |  | `ResetScenarios();`
|  | `492` |  | ``
| 0 | `493` |  | `return ResponseMessageBuilder.Create("Mappings deleted");`
| 0 | `494` |  | `}`
|  | `495` |  | `#endregion Mappings`
|  | `496` |  | ``
|  | `497` |  | `#region Request/{guid}`
|  | `498` |  | `private ResponseMessage RequestGet(RequestMessage requestMessage)`
| 0 | `499` |  | `{`
| 0 | `500` |  | `Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminRequests.Length + 1));`
| 0 | `501` |  | `var entry = LogEntries.FirstOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid)`
|  | `502` |  | ``
| 0 | `503` |  | `if (entry == null)`
| 0 | `504` |  | `{`
| 0 | `505` |  | `_logger.Warn("HttpStatusCode set to 404 : Request not found");`
| 0 | `506` |  | `return ResponseMessageBuilder.Create("Request not found", 404);`
|  | `507` |  | `}`
|  | `508` |  | ``
| 0 | `509` |  | `var model = LogEntryMapper.Map(entry);`
|  | `510` |  | ``
| 0 | `511` |  | `return ToJson(model);`
| 0 | `512` |  | `}`
|  | `513` |  | ``
|  | `514` |  | `private ResponseMessage RequestDelete(RequestMessage requestMessage)`
| 0 | `515` |  | `{`
| 0 | `516` |  | `Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminRequests.Length + 1));`
|  | `517` |  | ``
| 0 | `518` |  | `if (DeleteLogEntry(guid))`
| 0 | `519` |  | `{`
| 0 | `520` |  | `return ResponseMessageBuilder.Create("Request removed");`
|  | `521` |  | `}`
|  | `522` |  | ``
| 0 | `523` |  | `return ResponseMessageBuilder.Create("Request not found", 404);`
| 0 | `524` |  | `}`
|  | `525` |  | `#endregion Request/{guid}`
|  | `526` |  | ``
|  | `527` |  | `#region Requests`
|  | `528` |  | `private ResponseMessage RequestsGet(RequestMessage requestMessage)`
| 3 | `529` |  | `{`
| 3 | `530` |  | `var result = LogEntries`
| 6 | `531` |  | `.Where(r => !r.RequestMessage.Path.StartsWith("/__admin/"))`
| 3 | `532` |  | `.Select(LogEntryMapper.Map);`
|  | `533` |  | ``
| 3 | `534` |  | `return ToJson(result);`
| 3 | `535` |  | `}`
|  | `536` |  | ``
|  | `537` |  | `private ResponseMessage RequestsDelete(RequestMessage requestMessage)`
| 0 | `538` |  | `{`
| 0 | `539` |  | `ResetLogEntries();`
|  | `540` |  | ``
| 0 | `541` |  | `return ResponseMessageBuilder.Create("Requests deleted");`
| 0 | `542` |  | `}`
|  | `543` |  | `#endregion Requests`
|  | `544` |  | ``
|  | `545` |  | `#region Requests/find`
|  | `546` |  | `private ResponseMessage RequestsFind(RequestMessage requestMessage)`
| 1 | `547` |  | `{`
| 1 | `548` |  | `var requestModel = DeserializeObject<RequestModel>(requestMessage);`
|  | `549` |  | ``
| 1 | `550` |  | `var request = (Request)InitRequestBuilder(requestModel, false);`
|  | `551` |  | ``
| 1 | `552` |  | `var dict = new Dictionary<LogEntry, RequestMatchResult>();`
| 6 | `553` |  | `foreach (var logEntry in LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/")))`
| 1 | `554` |  | `{`
| 1 | `555` |  | `var requestMatchResult = new RequestMatchResult();`
| 1 | `556` |  | `if (request.GetMatchingScore(logEntry.RequestMessage, requestMatchResult) > MatchScores.AlmostPerfect)`
| 1 | `557` |  | `{`
| 1 | `558` |  | `dict.Add(logEntry, requestMatchResult);`
| 1 | `559` |  | `}`
| 1 | `560` |  | `}`
|  | `561` |  | ``
| 3 | `562` |  | `var result = dict.OrderBy(x => x.Value.AverageTotalScore).Select(x => x.Key).Select(LogEntryMapper.Map);`
|  | `563` |  | ``
| 1 | `564` |  | `return ToJson(result);`
| 1 | `565` |  | `}`
|  | `566` |  | `#endregion Requests/find`
|  | `567` |  | ``
|  | `568` |  | `#region Scenarios`
|  | `569` |  | `private ResponseMessage ScenariosGet(RequestMessage requestMessage)`
| 0 | `570` |  | `{`
| 0 | `571` |  | `var scenariosStates = Scenarios.Values.Select(s => new ScenarioStateModel`
| 0 | `572` |  | `{`
| 0 | `573` |  | `Name = s.Name,`
| 0 | `574` |  | `NextState = s.NextState,`
| 0 | `575` |  | `Started = s.Started,`
| 0 | `576` |  | `Finished = s.Finished`
| 0 | `577` |  | `});`
|  | `578` |  | ``
| 0 | `579` |  | `return ToJson(scenariosStates, true);`
| 0 | `580` |  | `}`
|  | `581` |  | ``
|  | `582` |  | `private ResponseMessage ScenariosReset(RequestMessage requestMessage)`
| 0 | `583` |  | `{`
| 0 | `584` |  | `ResetScenarios();`
|  | `585` |  | ``
| 0 | `586` |  | `return ResponseMessageBuilder.Create("Scenarios reset");`
| 0 | `587` |  | `}`
|  | `588` |  | `#endregion`
|  | `589` |  | ``
|  | `590` |  | `private IRequestBuilder InitRequestBuilder(RequestModel requestModel, bool pathOrUrlRequired)`
| 12 | `591` |  | `{`
| 12 | `592` |  | `IRequestBuilder requestBuilder = Request.Create();`
|  | `593` |  | ``
| 12 | `594` |  | `if (requestModel.ClientIP != null)`
| 0 | `595` |  | `{`
| 0 | `596` |  | `if (requestModel.ClientIP is string clientIP)`
| 0 | `597` |  | `{`
| 0 | `598` |  | `requestBuilder = requestBuilder.WithClientIP(clientIP);`
| 0 | `599` |  | `}`
|  | `600` |  | `else`
| 0 | `601` |  | `{`
| 0 | `602` |  | `var clientIPModel = JsonUtils.ParseJTokenToObject<ClientIPModel>(requestModel.ClientIP);`
| 0 | `603` |  | `if (clientIPModel?.Matchers != null)`
| 0 | `604` |  | `{`
| 0 | `605` |  | `requestBuilder = requestBuilder.WithPath(clientIPModel.Matchers.Select(MatcherMapper.Map).Cast<I`
| 0 | `606` |  | `}`
| 0 | `607` |  | `}`
| 0 | `608` |  | `}`
|  | `609` |  | ``
| 12 | `610` |  | `bool pathOrUrlmatchersValid = false;`
| 12 | `611` |  | `if (requestModel.Path != null)`
| 11 | `612` |  | `{`
| 11 | `613` |  | `if (requestModel.Path is string path)`
| 1 | `614` |  | `{`
| 1 | `615` |  | `requestBuilder = requestBuilder.WithPath(path);`
| 1 | `616` |  | `pathOrUrlmatchersValid = true;`
| 1 | `617` |  | `}`
|  | `618` |  | `else`
| 10 | `619` |  | `{`
| 10 | `620` |  | `var pathModel = JsonUtils.ParseJTokenToObject<PathModel>(requestModel.Path);`
| 10 | `621` |  | `if (pathModel?.Matchers != null)`
| 10 | `622` |  | `{`
| 10 | `623` |  | `requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(MatcherMapper.Map).Cast<IStri`
| 10 | `624` |  | `pathOrUrlmatchersValid = true;`
| 10 | `625` |  | `}`
| 10 | `626` |  | `}`
| 11 | `627` |  | `}`
| 1 | `628` |  | `else if (requestModel.Url != null)`
| 0 | `629` |  | `{`
| 0 | `630` |  | `if (requestModel.Url is string url)`
| 0 | `631` |  | `{`
| 0 | `632` |  | `requestBuilder = requestBuilder.WithUrl(url);`
| 0 | `633` |  | `pathOrUrlmatchersValid = true;`
| 0 | `634` |  | `}`
|  | `635` |  | `else`
| 0 | `636` |  | `{`
| 0 | `637` |  | `var urlModel = JsonUtils.ParseJTokenToObject<UrlModel>(requestModel.Url);`
| 0 | `638` |  | `if (urlModel?.Matchers != null)`
| 0 | `639` |  | `{`
| 0 | `640` |  | `requestBuilder = requestBuilder.WithUrl(urlModel.Matchers.Select(MatcherMapper.Map).Cast<IString`
| 0 | `641` |  | `pathOrUrlmatchersValid = true;`
| 0 | `642` |  | `}`
| 0 | `643` |  | `}`
| 0 | `644` |  | `}`
|  | `645` |  | ``
| 12 | `646` |  | `if (pathOrUrlRequired && !pathOrUrlmatchersValid)`
| 0 | `647` |  | `{`
| 0 | `648` |  | `_logger.Error("Path or Url matcher is missing for this mapping, this mapping will not be added.");`
| 0 | `649` |  | `return null;`
|  | `650` |  | `}`
|  | `651` |  | ``
| 12 | `652` |  | `if (requestModel.Methods != null)`
| 11 | `653` |  | `{`
| 11 | `654` |  | `requestBuilder = requestBuilder.UsingMethod(requestModel.Methods);`
| 11 | `655` |  | `}`
|  | `656` |  | ``
| 12 | `657` |  | `if (requestModel.Headers != null)`
| 0 | `658` |  | `{`
| 0 | `659` |  | `foreach (var headerModel in requestModel.Headers.Where(h => h.Matchers != null))`
| 0 | `660` |  | `{`
| 0 | `661` |  | `requestBuilder = requestBuilder.WithHeader(headerModel.Name, headerModel.Matchers.Select(MatcherMapp`
| 0 | `662` |  | `}`
| 0 | `663` |  | `}`
|  | `664` |  | ``
| 12 | `665` |  | `if (requestModel.Cookies != null)`
| 0 | `666` |  | `{`
| 0 | `667` |  | `foreach (var cookieModel in requestModel.Cookies.Where(c => c.Matchers != null))`
| 0 | `668` |  | `{`
| 0 | `669` |  | `requestBuilder = requestBuilder.WithCookie(cookieModel.Name, cookieModel.Matchers.Select(MatcherMapp`
| 0 | `670` |  | `}`
| 0 | `671` |  | `}`
|  | `672` |  | ``
| 12 | `673` |  | `if (requestModel.Params != null)`
| 0 | `674` |  | `{`
| 0 | `675` |  | `foreach (var paramModel in requestModel.Params.Where(c => c.Matchers != null))`
| 0 | `676` |  | `{`
| 0 | `677` |  | `requestBuilder = requestBuilder.WithParam(paramModel.Name, paramModel.Matchers.Select(MatcherMapper.`
| 0 | `678` |  | `}`
| 0 | `679` |  | `}`
|  | `680` |  | ``
| 12 | `681` |  | `if (requestModel.Body?.Matcher != null)`
| 3 | `682` |  | `{`
| 3 | `683` |  | `var bodyMatcher = MatcherMapper.Map(requestModel.Body.Matcher);`
| 3 | `684` |  | `requestBuilder = requestBuilder.WithBody(bodyMatcher);`
| 3 | `685` |  | `}`
|  | `686` |  | ``
| 12 | `687` |  | `return requestBuilder;`
| 12 | `688` |  | `}`
|  | `689` |  | ``
|  | `690` |  | `private IResponseBuilder InitResponseBuilder(ResponseModel responseModel)`
| 11 | `691` |  | `{`
| 11 | `692` |  | `IResponseBuilder responseBuilder = Response.Create();`
|  | `693` |  | ``
| 11 | `694` |  | `if (responseModel.Delay > 0)`
| 0 | `695` |  | `{`
| 0 | `696` |  | `responseBuilder = responseBuilder.WithDelay(responseModel.Delay.Value);`
| 0 | `697` |  | `}`
|  | `698` |  | ``
| 11 | `699` |  | `if (!string.IsNullOrEmpty(responseModel.ProxyUrl))`
| 0 | `700` |  | `{`
| 0 | `701` |  | `if (string.IsNullOrEmpty(responseModel.X509Certificate2ThumbprintOrSubjectName))`
| 0 | `702` |  | `{`
| 0 | `703` |  | `return responseBuilder.WithProxy(responseModel.ProxyUrl);`
|  | `704` |  | `}`
|  | `705` |  | ``
| 0 | `706` |  | `return responseBuilder.WithProxy(responseModel.ProxyUrl, responseModel.X509Certificate2ThumbprintOrSubje`
|  | `707` |  | `}`
|  | `708` |  | ``
| 11 | `709` |  | `if (responseModel.StatusCode.HasValue)`
| 10 | `710` |  | `{`
| 10 | `711` |  | `responseBuilder = responseBuilder.WithStatusCode(responseModel.StatusCode.Value);`
| 10 | `712` |  | `}`
|  | `713` |  | ``
| 11 | `714` |  | `if (responseModel.Headers != null)`
| 9 | `715` |  | `{`
| 189 | `716` |  | `foreach (var entry in responseModel.Headers)`
| 81 | `717` |  | `{`
| 81 | `718` |  | `responseBuilder = entry.Value is string value ?`
| 81 | `719` |  | `responseBuilder.WithHeader(entry.Key, value) :`
| 81 | `720` |  | `responseBuilder.WithHeader(entry.Key, JsonUtils.ParseJTokenToObject<string[]>(entry.Value));`
| 81 | `721` |  | `}`
| 9 | `722` |  | `}`
| 2 | `723` |  | `else if (responseModel.HeadersRaw != null)`
| 0 | `724` |  | `{`
| 0 | `725` |  | `foreach (string headerLine in responseModel.HeadersRaw.Split(new[] { "\n", "\r\n" }, StringSplitOptions.`
| 0 | `726` |  | `{`
| 0 | `727` |  | `int indexColon = headerLine.IndexOf(":", StringComparison.Ordinal);`
| 0 | `728` |  | `string key = headerLine.Substring(0, indexColon).TrimStart(' ', '\t');`
| 0 | `729` |  | `string value = headerLine.Substring(indexColon + 1).TrimStart(' ', '\t');`
| 0 | `730` |  | `responseBuilder = responseBuilder.WithHeader(key, value);`
| 0 | `731` |  | `}`
| 0 | `732` |  | `}`
|  | `733` |  | ``
| 11 | `734` |  | `if (responseModel.BodyAsBytes != null)`
| 0 | `735` |  | `{`
| 0 | `736` |  | `responseBuilder = responseBuilder.WithBody(responseModel.BodyAsBytes, responseModel.BodyDestination, ToE`
| 0 | `737` |  | `}`
| 11 | `738` |  | `else if (responseModel.Body != null)`
| 7 | `739` |  | `{`
| 7 | `740` |  | `responseBuilder = responseBuilder.WithBody(responseModel.Body, responseModel.BodyDestination, ToEncoding`
| 7 | `741` |  | `}`
| 4 | `742` |  | `else if (responseModel.BodyAsJson != null)`
| 1 | `743` |  | `{`
| 1 | `744` |  | `responseBuilder = responseBuilder.WithBodyAsJson(responseModel.BodyAsJson, ToEncoding(responseModel.Body`
| 1 | `745` |  | `}`
| 3 | `746` |  | `else if (responseModel.BodyFromBase64 != null)`
| 0 | `747` |  | `{`
| 0 | `748` |  | `responseBuilder = responseBuilder.WithBodyFromBase64(responseModel.BodyFromBase64, ToEncoding(responseMo`
| 0 | `749` |  | `}`
| 3 | `750` |  | `else if (responseModel.BodyAsFile != null)`
| 3 | `751` |  | `{`
| 3 | `752` |  | `responseBuilder = responseBuilder.WithBodyFromFile(responseModel.BodyAsFile);`
| 3 | `753` |  | `}`
|  | `754` |  | ``
| 11 | `755` |  | `if (responseModel.UseTransformer)`
| 0 | `756` |  | `{`
| 0 | `757` |  | `responseBuilder = responseBuilder.WithTransformer();`
| 0 | `758` |  | `}`
|  | `759` |  | ``
| 11 | `760` |  | `return responseBuilder;`
| 11 | `761` |  | `}`
|  | `762` |  | ``
|  | `763` |  | `private ResponseMessage ToJson<T>(T result, bool keepNullValues = false)`
| 5 | `764` |  | `{`
| 5 | `765` |  | `return new ResponseMessage`
| 5 | `766` |  | `{`
| 5 | `767` |  | `Body = JsonConvert.SerializeObject(result, keepNullValues ? _settingsIncludeNullValues : _settings),`
| 5 | `768` |  | `StatusCode = 200,`
| 5 | `769` |  | `Headers = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMoc`
| 5 | `770` |  | `};`
| 5 | `771` |  | `}`
|  | `772` |  | ``
|  | `773` |  | `private Encoding ToEncoding(EncodingModel encodingModel)`
| 8 | `774` |  | `{`
| 8 | `775` |  | `return encodingModel != null ? Encoding.GetEncoding(encodingModel.CodePage) : null;`
| 8 | `776` |  | `}`
|  | `777` |  | ``
|  | `778` |  | `private T DeserializeObject<T>(RequestMessage requestMessage)`
| 4 | `779` |  | `{`
| 4 | `780` |  | `return requestMessage.Body != null ?`
| 4 | `781` |  | `JsonConvert.DeserializeObject<T>(requestMessage.Body) :`
| 4 | `782` |  | `((JObject)requestMessage.BodyAsJson).ToObject<T>();`
| 4 | `783` |  | `}`
|  | `784` |  | `}`
|  | `785` |  | `}`

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using JetBrains.Annotations;`
|  | `2` |  | `using System;`
|  | `3` |  | `using System.Collections.Concurrent;`
|  | `4` |  | `using System.Collections.Generic;`
|  | `5` |  | `using System.Linq;`
|  | `6` |  | `using System.Text;`
|  | `7` |  | `using System.Threading;`
|  | `8` |  | `using Newtonsoft.Json;`
|  | `9` |  | `using WireMock.Handlers;`
|  | `10` |  | `using WireMock.Logging;`
|  | `11` |  | `using WireMock.Matchers;`
|  | `12` |  | `using WireMock.Matchers.Request;`
|  | `13` |  | `using WireMock.Owin;`
|  | `14` |  | `using WireMock.RequestBuilders;`
|  | `15` |  | `using WireMock.ResponseProviders;`
|  | `16` |  | `using WireMock.Settings;`
|  | `17` |  | `using WireMock.Util;`
|  | `18` |  | `using WireMock.Validation;`
|  | `19` |  | ``
|  | `20` |  | `namespace WireMock.Server`
|  | `21` |  | `{`
|  | `22` |  | `/// <summary>`
|  | `23` |  | `/// The fluent mock server.`
|  | `24` |  | `/// </summary>`
|  | `25` |  | `public partial class FluentMockServer : IDisposable`
|  | `26` |  | `{`
|  | `27` |  | `private readonly IWireMockLogger _logger;`
|  | `28` |  | `private readonly IFileSystemHandler _fileSystemHandler;`
|  | `29` |  | ``
|  | `30` |  | `private const int ServerStartDelay = 100;`
|  | `31` |  | `private readonly IOwinSelfHost _httpServer;`
| 55 | `32` |  | `private readonly WireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();`
|  | `33` |  | ``
|  | `34` |  | `/// <summary>`
|  | `35` |  | `/// Gets a value indicating whether this server is started.`
|  | `36` |  | `/// </summary>`
|  | `37` |  | `[PublicAPI]`
| 0 | `38` |  | `public bool IsStarted => _httpServer != null && _httpServer.IsStarted;`
|  | `39` |  | ``
|  | `40` |  | `/// <summary>`
|  | `41` |  | `/// Gets the ports.`
|  | `42` |  | `/// </summary>`
|  | `43` |  | `[PublicAPI]`
| 40 | `44` |  | `public List<int> Ports { get; }`
|  | `45` |  | ``
|  | `46` |  | `/// <summary>`
|  | `47` |  | `/// Gets the urls.`
|  | `48` |  | `/// </summary>`
|  | `49` |  | `[PublicAPI]`
| 72 | `50` |  | `public string[] Urls { get; }`
|  | `51` |  | ``
|  | `52` |  | `/// <summary>`
|  | `53` |  | `/// Gets the mappings.`
|  | `54` |  | `/// </summary>`
|  | `55` |  | `[PublicAPI]`
| 18 | `56` |  | `public IEnumerable<Mapping> Mappings => _options.Mappings.Values.ToArray();`
|  | `57` |  | ``
|  | `58` |  | `/// <summary>`
|  | `59` |  | `/// Gets the scenarios.`
|  | `60` |  | `/// </summary>`
|  | `61` |  | `[PublicAPI]`
| 13 | `62` |  | `public ConcurrentDictionary<string, ScenarioState> Scenarios => new ConcurrentDictionary<string, ScenarioState>(`
|  | `63` |  | ``
|  | `64` |  | `#region IDisposable Members`
|  | `65` |  | `/// <summary>`
|  | `66` |  | `/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.`
|  | `67` |  | `/// </summary>`
|  | `68` |  | `public void Dispose()`
| 0 | `69` |  | `{`
| 0 | `70` |  | `Dispose(true);`
| 0 | `71` |  | `GC.SuppressFinalize(this);`
| 0 | `72` |  | `}`
|  | `73` |  | ``
|  | `74` |  | `/// <summary>`
|  | `75` |  | `/// Releases unmanaged and - optionally - managed resources.`
|  | `76` |  | `/// </summary>`
|  | `77` |  | `/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release`
|  | `78` |  | `protected virtual void Dispose(bool disposing)`
| 0 | `79` |  | `{`
| 0 | `80` |  | `if (_httpServer != null)`
| 0 | `81` |  | `{`
| 0 | `82` |  | `_httpServer.StopAsync();`
| 0 | `83` |  | `}`
| 0 | `84` |  | `}`
|  | `85` |  | `#endregion`
|  | `86` |  | ``
|  | `87` |  | `#region Start/Stop`
|  | `88` |  | `/// <summary>`
|  | `89` |  | `/// Starts the specified settings.`
|  | `90` |  | `/// </summary>`
|  | `91` |  | `/// <param name="settings">The FluentMockServerSettings.</param>`
|  | `92` |  | `/// <returns>The <see cref="FluentMockServer"/>.</returns>`
|  | `93` |  | `[PublicAPI]`
|  | `94` |  | `public static FluentMockServer Start(IFluentMockServerSettings settings)`
| 14 | `95` |  | `{`
| 14 | `96` |  | `Check.NotNull(settings, nameof(settings));`
|  | `97` |  | ``
| 14 | `98` |  | `return new FluentMockServer(settings);`
| 14 | `99` |  | `}`
|  | `100` |  | ``
|  | `101` |  | `/// <summary>`
|  | `102` |  | `/// Start this FluentMockServer.`
|  | `103` |  | `/// </summary>`
|  | `104` |  | `/// <param name="port">The port.</param>`
|  | `105` |  | `/// <param name="ssl">The SSL support.</param>`
|  | `106` |  | `/// <returns>The <see cref="FluentMockServer"/>.</returns>`
|  | `107` |  | `[PublicAPI]`
|  | `108` |  | `public static FluentMockServer Start([CanBeNull] int? port = 0, bool ssl = false)`
| 36 | `109` |  | `{`
| 36 | `110` |  | `return new FluentMockServer(new FluentMockServerSettings`
| 36 | `111` |  | `{`
| 36 | `112` |  | `Port = port,`
| 36 | `113` |  | `UseSSL = ssl`
| 36 | `114` |  | `});`
| 36 | `115` |  | `}`
|  | `116` |  | ``
|  | `117` |  | `/// <summary>`
|  | `118` |  | `/// Start this FluentMockServer.`
|  | `119` |  | `/// </summary>`
|  | `120` |  | `/// <param name="urls">The urls to listen on.</param>`
|  | `121` |  | `/// <returns>The <see cref="FluentMockServer"/>.</returns>`
|  | `122` |  | `[PublicAPI]`
|  | `123` |  | `public static FluentMockServer Start(params string[] urls)`
| 1 | `124` |  | `{`
| 1 | `125` |  | `Check.NotNullOrEmpty(urls, nameof(urls));`
|  | `126` |  | ``
| 1 | `127` |  | `return new FluentMockServer(new FluentMockServerSettings`
| 1 | `128` |  | `{`
| 1 | `129` |  | `Urls = urls`
| 1 | `130` |  | `});`
| 1 | `131` |  | `}`
|  | `132` |  | ``
|  | `133` |  | `/// <summary>`
|  | `134` |  | `/// Start this FluentMockServer with the admin interface.`
|  | `135` |  | `/// </summary>`
|  | `136` |  | `/// <param name="port">The port.</param>`
|  | `137` |  | `/// <param name="ssl">The SSL support.</param>`
|  | `138` |  | `/// <returns>The <see cref="FluentMockServer"/>.</returns>`
|  | `139` |  | `[PublicAPI]`
|  | `140` |  | `public static FluentMockServer StartWithAdminInterface(int? port = 0, bool ssl = false)`
| 4 | `141` |  | `{`
| 4 | `142` |  | `return new FluentMockServer(new FluentMockServerSettings`
| 4 | `143` |  | `{`
| 4 | `144` |  | `Port = port,`
| 4 | `145` |  | `UseSSL = ssl,`
| 4 | `146` |  | `StartAdminInterface = true`
| 4 | `147` |  | `});`
| 4 | `148` |  | `}`
|  | `149` |  | ``
|  | `150` |  | `/// <summary>`
|  | `151` |  | `/// Start this FluentMockServer with the admin interface.`
|  | `152` |  | `/// </summary>`
|  | `153` |  | `/// <param name="urls">The urls.</param>`
|  | `154` |  | `/// <returns>The <see cref="FluentMockServer"/>.</returns>`
|  | `155` |  | `[PublicAPI]`
|  | `156` |  | `public static FluentMockServer StartWithAdminInterface(params string[] urls)`
| 0 | `157` |  | `{`
| 0 | `158` |  | `Check.NotNullOrEmpty(urls, nameof(urls));`
|  | `159` |  | ``
| 0 | `160` |  | `return new FluentMockServer(new FluentMockServerSettings`
| 0 | `161` |  | `{`
| 0 | `162` |  | `Urls = urls,`
| 0 | `163` |  | `StartAdminInterface = true`
| 0 | `164` |  | `});`
| 0 | `165` |  | `}`
|  | `166` |  | ``
|  | `167` |  | `/// <summary>`
|  | `168` |  | `/// Start this FluentMockServer with the admin interface and read static mappings.`
|  | `169` |  | `/// </summary>`
|  | `170` |  | `/// <param name="urls">The urls.</param>`
|  | `171` |  | `/// <returns>The <see cref="FluentMockServer"/>.</returns>`
|  | `172` |  | `[PublicAPI]`
|  | `173` |  | `public static FluentMockServer StartWithAdminInterfaceAndReadStaticMappings(params string[] urls)`
| 0 | `174` |  | `{`
| 0 | `175` |  | `Check.NotNullOrEmpty(urls, nameof(urls));`
|  | `176` |  | ``
| 0 | `177` |  | `return new FluentMockServer(new FluentMockServerSettings`
| 0 | `178` |  | `{`
| 0 | `179` |  | `Urls = urls,`
| 0 | `180` |  | `StartAdminInterface = true,`
| 0 | `181` |  | `ReadStaticMappings = true`
| 0 | `182` |  | `});`
| 0 | `183` |  | `}`
|  | `184` |  | ``
| 55 | `185` |  | `private FluentMockServer(IFluentMockServerSettings settings)`
| 55 | `186` |  | `{`
| 55 | `187` |  | `settings.Logger = settings.Logger ?? new WireMockConsoleLogger();`
|  | `188` |  | ``
| 55 | `189` |  | `_logger = settings.Logger;`
| 55 | `190` |  | `_fileSystemHandler = settings.FileSystemHandler ?? new LocalFileSystemHandler();`
|  | `191` |  | ``
| 55 | `192` |  | `_logger.Info("WireMock.Net by Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)");`
| 55 | `193` |  | `_logger.Debug("WireMock.Net server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented)`
|  | `194` |  | ``
| 55 | `195` |  | `if (settings.Urls != null)`
| 1 | `196` |  | `{`
| 1 | `197` |  | `Urls = settings.Urls.ToArray();`
| 1 | `198` |  | `}`
|  | `199` |  | `else`
| 54 | `200` |  | `{`
| 54 | `201` |  | `int port = settings.Port > 0 ? settings.Port.Value : PortUtils.FindFreeTcpPort();`
| 54 | `202` |  | `Urls = new[] { $"{(settings.UseSSL == true ? "https" : "http")}://localhost:{port}" };`
| 54 | `203` |  | `}`
|  | `204` |  | ``
| 55 | `205` |  | `_options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit;`
| 55 | `206` |  | `_options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit;`
| 55 | `207` |  | `_options.Logger = _logger;`
|  | `208` |  | ``
|  | `209` |  | `#if USE_ASPNETCORE`
| 55 | `210` |  | `_httpServer = new AspNetCoreSelfHost(_options, Urls);`
|  | `211` |  | `#else`
|  | `212` |  | `_httpServer = new OwinSelfHost(_options, Urls);`
|  | `213` |  | `#endif`
| 55 | `214` |  | `Ports = _httpServer.Ports;`
|  | `215` |  | ``
| 55 | `216` |  | `_httpServer.StartAsync();`
|  | `217` |  | ``
| 55 | `218` |  | `using (var ctsStartTimeout = new CancellationTokenSource(settings.StartTimeout))`
| 55 | `219` |  | `{`
| 451 | `220` |  | `while (!_httpServer.IsStarted)`
| 396 | `221` |  | `{`
|  | `222` |  | `// Throw out exception if service start fails`
| 396 | `223` |  | `if (_httpServer.RunningException != null)`
| 0 | `224` |  | `{`
| 0 | `225` |  | `throw new Exception($"Service start failed with error: {_httpServer.RunningException.Message}",`
|  | `226` |  | `}`
|  | `227` |  | ``
|  | `228` |  | `// Respect start timeout setting by throwing TimeoutException`
| 396 | `229` |  | `if (ctsStartTimeout.IsCancellationRequested)`
| 0 | `230` |  | `{`
| 0 | `231` |  | `throw new TimeoutException($"Service start timed out after {TimeSpan.FromMilliseconds(settings.S`
|  | `232` |  | `}`
|  | `233` |  | ``
| 396 | `234` |  | `ctsStartTimeout.Token.WaitHandle.WaitOne(ServerStartDelay);`
| 396 | `235` |  | `}`
| 55 | `236` |  | `}`
|  | `237` |  | ``
| 55 | `238` |  | `if (settings.AllowPartialMapping == true)`
| 0 | `239` |  | `{`
| 0 | `240` |  | `AllowPartialMapping();`
| 0 | `241` |  | `}`
|  | `242` |  | ``
| 55 | `243` |  | `if (settings.StartAdminInterface == true)`
| 11 | `244` |  | `{`
| 11 | `245` |  | `if (!string.IsNullOrEmpty(settings.AdminUsername) && !string.IsNullOrEmpty(settings.AdminPassword))`
| 1 | `246` |  | `{`
| 1 | `247` |  | `SetBasicAuthentication(settings.AdminUsername, settings.AdminPassword);`
| 1 | `248` |  | `}`
|  | `249` |  | ``
| 11 | `250` |  | `InitAdmin();`
| 11 | `251` |  | `}`
|  | `252` |  | ``
| 55 | `253` |  | `if (settings.ReadStaticMappings == true)`
| 0 | `254` |  | `{`
| 0 | `255` |  | `ReadStaticMappings();`
| 0 | `256` |  | `}`
|  | `257` |  | ``
| 55 | `258` |  | `if (settings.WatchStaticMappings == true)`
| 0 | `259` |  | `{`
| 0 | `260` |  | `WatchStaticMappings();`
| 0 | `261` |  | `}`
|  | `262` |  | ``
| 55 | `263` |  | `if (settings.ProxyAndRecordSettings != null)`
| 2 | `264` |  | `{`
| 2 | `265` |  | `InitProxyAndRecord(settings);`
| 2 | `266` |  | `}`
|  | `267` |  | ``
| 55 | `268` |  | `if (settings.MaxRequestLogCount != null)`
| 0 | `269` |  | `{`
| 0 | `270` |  | `SetMaxRequestLogCount(settings.MaxRequestLogCount);`
| 0 | `271` |  | `}`
| 55 | `272` |  | `}`
|  | `273` |  | ``
|  | `274` |  | `/// <summary>`
|  | `275` |  | `/// Stop this server.`
|  | `276` |  | `/// </summary>`
|  | `277` |  | `[PublicAPI]`
|  | `278` |  | `public void Stop()`
| 2 | `279` |  | `{`
| 2 | `280` |  | `var result = _httpServer?.StopAsync();`
| 2 | `281` |  | `result?.Wait(); // wait for stop to actually happen`
| 2 | `282` |  | `}`
|  | `283` |  | `#endregion`
|  | `284` |  | ``
|  | `285` |  | `/// <summary>`
|  | `286` |  | `/// Adds the catch all mapping.`
|  | `287` |  | `/// </summary>`
|  | `288` |  | `[PublicAPI]`
|  | `289` |  | `public void AddCatchAllMapping()`
| 0 | `290` |  | `{`
| 0 | `291` |  | `Given(Request.Create().WithPath("/*").UsingAnyMethod())`
| 0 | `292` |  | `.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))`
| 0 | `293` |  | `.AtPriority(1000)`
| 0 | `294` |  | `.RespondWith(new DynamicResponseProvider(request => ResponseMessageBuilder.Create("No matching mapping f`
| 0 | `295` |  | `}`
|  | `296` |  | ``
|  | `297` |  | `/// <summary>`
|  | `298` |  | `/// Resets LogEntries and Mappings.`
|  | `299` |  | `/// </summary>`
|  | `300` |  | `[PublicAPI]`
|  | `301` |  | `public void Reset()`
| 0 | `302` |  | `{`
| 0 | `303` |  | `ResetLogEntries();`
|  | `304` |  | ``
| 0 | `305` |  | `ResetMappings();`
| 0 | `306` |  | `}`
|  | `307` |  | ``
|  | `308` |  | `/// <summary>`
|  | `309` |  | `/// Resets the Mappings.`
|  | `310` |  | `/// </summary>`
|  | `311` |  | `[PublicAPI]`
|  | `312` |  | `public void ResetMappings()`
| 10 | `313` |  | `{`
| 66 | `314` |  | `foreach (var nonAdmin in _options.Mappings.ToArray().Where(m => !m.Value.IsAdminInterface))`
| 12 | `315` |  | `{`
| 12 | `316` |  | `_options.Mappings.TryRemove(nonAdmin.Key, out _);`
| 12 | `317` |  | `}`
| 10 | `318` |  | `}`
|  | `319` |  | ``
|  | `320` |  | `/// <summary>`
|  | `321` |  | `/// Deletes the mapping.`
|  | `322` |  | `/// </summary>`
|  | `323` |  | `/// <param name="guid">The unique identifier.</param>`
|  | `324` |  | `[PublicAPI]`
|  | `325` |  | `public bool DeleteMapping(Guid guid)`
| 0 | `326` |  | `{`
|  | `327` |  | `// Check a mapping exists with the same GUID, if so, remove it.`
| 0 | `328` |  | `if (_options.Mappings.ContainsKey(guid))`
| 0 | `329` |  | `{`
| 0 | `330` |  | `return _options.Mappings.TryRemove(guid, out _);`
|  | `331` |  | `}`
|  | `332` |  | ``
| 0 | `333` |  | `return false;`
| 0 | `334` |  | `}`
|  | `335` |  | ``
|  | `336` |  | `private bool DeleteMapping(string path)`
| 0 | `337` |  | `{`
|  | `338` |  | `// Check a mapping exists with the same path, if so, remove it.`
| 0 | `339` |  | `var mapping = _options.Mappings.ToArray().FirstOrDefault(entry => string.Equals(entry.Value.Path, path, Stri`
| 0 | `340` |  | `return DeleteMapping(mapping.Key);`
| 0 | `341` |  | `}`
|  | `342` |  | ``
|  | `343` |  | `/// <summary>`
|  | `344` |  | `/// The add request processing delay.`
|  | `345` |  | `/// </summary>`
|  | `346` |  | `/// <param name="delay">The delay.</param>`
|  | `347` |  | `[PublicAPI]`
|  | `348` |  | `public void AddGlobalProcessingDelay(TimeSpan delay)`
| 1 | `349` |  | `{`
| 1 | `350` |  | `_options.RequestProcessingDelay = delay;`
| 1 | `351` |  | `}`
|  | `352` |  | ``
|  | `353` |  | `/// <summary>`
|  | `354` |  | `/// Allows the partial mapping.`
|  | `355` |  | `/// </summary>`
|  | `356` |  | `[PublicAPI]`
|  | `357` |  | `public void AllowPartialMapping(bool allow = true)`
| 0 | `358` |  | `{`
| 0 | `359` |  | `_logger.Info("AllowPartialMapping is set to {0}", allow);`
| 0 | `360` |  | `_options.AllowPartialMapping = allow;`
| 0 | `361` |  | `}`
|  | `362` |  | ``
|  | `363` |  | `/// <summary>`
|  | `364` |  | `/// Sets the basic authentication.`
|  | `365` |  | `/// </summary>`
|  | `366` |  | `/// <param name="username">The username.</param>`
|  | `367` |  | `/// <param name="password">The password.</param>`
|  | `368` |  | `[PublicAPI]`
|  | `369` |  | `public void SetBasicAuthentication([NotNull] string username, [NotNull] string password)`
| 3 | `370` |  | `{`
| 3 | `371` |  | `Check.NotNull(username, nameof(username));`
| 3 | `372` |  | `Check.NotNull(password, nameof(password));`
|  | `373` |  | ``
| 3 | `374` |  | `string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + p`
| 3 | `375` |  | `_options.AuthorizationMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, "^(?i)BASIC " + authorization`
| 3 | `376` |  | `}`
|  | `377` |  | ``
|  | `378` |  | `/// <summary>`
|  | `379` |  | `/// Removes the basic authentication.`
|  | `380` |  | `/// </summary>`
|  | `381` |  | `[PublicAPI]`
|  | `382` |  | `public void RemoveBasicAuthentication()`
| 1 | `383` |  | `{`
| 1 | `384` |  | `_options.AuthorizationMatcher = null;`
| 1 | `385` |  | `}`
|  | `386` |  | ``
|  | `387` |  | `/// <summary>`
|  | `388` |  | `/// Sets the maximum RequestLog count.`
|  | `389` |  | `/// </summary>`
|  | `390` |  | `/// <param name="maxRequestLogCount">The maximum RequestLog count.</param>`
|  | `391` |  | `[PublicAPI]`
|  | `392` |  | `public void SetMaxRequestLogCount([CanBeNull] int? maxRequestLogCount)`
| 1 | `393` |  | `{`
| 1 | `394` |  | `_options.MaxRequestLogCount = maxRequestLogCount;`
| 1 | `395` |  | `}`
|  | `396` |  | ``
|  | `397` |  | `/// <summary>`
|  | `398` |  | `/// Sets RequestLog expiration in hours.`
|  | `399` |  | `/// </summary>`
|  | `400` |  | `/// <param name="requestLogExpirationDuration">The RequestLog expiration in hours.</param>`
|  | `401` |  | `[PublicAPI]`
|  | `402` |  | `public void SetRequestLogExpirationDuration([CanBeNull] int? requestLogExpirationDuration)`
| 0 | `403` |  | `{`
| 0 | `404` |  | `_options.RequestLogExpirationDuration = requestLogExpirationDuration;`
| 0 | `405` |  | `}`
|  | `406` |  | ``
|  | `407` |  | `/// <summary>`
|  | `408` |  | `/// Resets the Scenarios.`
|  | `409` |  | `/// </summary>`
|  | `410` |  | `[PublicAPI]`
|  | `411` |  | `public void ResetScenarios()`
| 0 | `412` |  | `{`
| 0 | `413` |  | `_options.Scenarios.Clear();`
| 0 | `414` |  | `}`
|  | `415` |  | ``
|  | `416` |  | `/// <summary>`
|  | `417` |  | `/// The given.`
|  | `418` |  | `/// </summary>`
|  | `419` |  | `/// <param name="requestMatcher">The request matcher.</param>`
|  | `420` |  | `/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>`
|  | `421` |  | `[PublicAPI]`
|  | `422` |  | `public IRespondWithAProvider Given(IRequestMatcher requestMatcher)`
| 264 | `423` |  | `{`
| 264 | `424` |  | `return new RespondWithAProvider(RegisterMapping, requestMatcher);`
| 264 | `425` |  | `}`
|  | `426` |  | ``
|  | `427` |  | `private void RegisterMapping(Mapping mapping)`
| 264 | `428` |  | `{`
|  | `429` |  | `// Check a mapping exists with the same Guid, if so, replace it.`
| 264 | `430` |  | `if (_options.Mappings.ContainsKey(mapping.Guid))`
| 1 | `431` |  | `{`
| 1 | `432` |  | `_options.Mappings[mapping.Guid] = mapping;`
| 1 | `433` |  | `}`
|  | `434` |  | `else`
| 263 | `435` |  | `{`
| 263 | `436` |  | `_options.Mappings.TryAdd(mapping.Guid, mapping);`
| 263 | `437` |  | `}`
| 264 | `438` |  | `}`
|  | `439` |  | `}`
|  | `440` |  | `}`

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Server\FluentMockServer.LogEntries.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Collections;`
|  | `3` |  | `using System.Collections.Generic;`
|  | `4` |  | `using System.Collections.ObjectModel;`
|  | `5` |  | `using System.Collections.Specialized;`
|  | `6` |  | `using JetBrains.Annotations;`
|  | `7` |  | `using WireMock.Logging;`
|  | `8` |  | `using WireMock.Matchers.Request;`
|  | `9` |  | `using System.Linq;`
|  | `10` |  | `using WireMock.Matchers;`
|  | `11` |  | ``
|  | `12` |  | `namespace WireMock.Server`
|  | `13` |  | `{`
|  | `14` |  | `public partial class FluentMockServer`
|  | `15` |  | `{`
|  | `16` |  | `/// <summary>`
|  | `17` |  | `/// Occurs when [log entries changed].`
|  | `18` |  | `/// </summary>`
|  | `19` |  | `[PublicAPI]`
|  | `20` |  | `public event NotifyCollectionChangedEventHandler LogEntriesChanged`
|  | `21` |  | `{`
| 2 | `22` |  | `add => _options.LogEntries.CollectionChanged += value;`
| 0 | `23` |  | `remove => _options.LogEntries.CollectionChanged -= value;`
|  | `24` |  | `}`
|  | `25` |  | ``
|  | `26` |  | `/// <summary>`
|  | `27` |  | `/// Gets the request logs.`
|  | `28` |  | `/// </summary>`
|  | `29` |  | `[PublicAPI]`
| 12 | `30` |  | `public IEnumerable<LogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries);`
|  | `31` |  | ``
|  | `32` |  | `/// <summary>`
|  | `33` |  | `/// The search log-entries based on matchers.`
|  | `34` |  | `/// </summary>`
|  | `35` |  | `/// <param name="matchers">The matchers.</param>`
|  | `36` |  | `/// <returns>The <see cref="IEnumerable"/>.</returns>`
|  | `37` |  | `[PublicAPI]`
|  | `38` |  | `public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)`
| 1 | `39` |  | `{`
| 1 | `40` |  | `var results = new Dictionary<LogEntry, RequestMatchResult>();`
|  | `41` |  | ``
| 7 | `42` |  | `foreach (var log in _options.LogEntries)`
| 2 | `43` |  | `{`
| 2 | `44` |  | `var requestMatchResult = new RequestMatchResult();`
| 10 | `45` |  | `foreach (var matcher in matchers)`
| 2 | `46` |  | `{`
| 2 | `47` |  | `matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);`
| 2 | `48` |  | `}`
|  | `49` |  | ``
| 2 | `50` |  | `if (requestMatchResult.AverageTotalScore > MatchScores.AlmostPerfect)`
| 1 | `51` |  | `{`
| 1 | `52` |  | `results.Add(log, requestMatchResult);`
| 1 | `53` |  | `}`
| 2 | `54` |  | `}`
|  | `55` |  | ``
| 3 | `56` |  | `return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());`
| 1 | `57` |  | `}`
|  | `58` |  | ``
|  | `59` |  | `/// <summary>`
|  | `60` |  | `/// Resets the LogEntries.`
|  | `61` |  | `/// </summary>`
|  | `62` |  | `[PublicAPI]`
|  | `63` |  | `public void ResetLogEntries()`
| 9 | `64` |  | `{`
| 9 | `65` |  | `_options.LogEntries.Clear();`
| 9 | `66` |  | `}`
|  | `67` |  | ``
|  | `68` |  | `/// <summary>`
|  | `69` |  | `/// Deletes a LogEntry.`
|  | `70` |  | `/// </summary>`
|  | `71` |  | `/// <param name="guid">The unique identifier.</param>`
|  | `72` |  | `[PublicAPI]`
|  | `73` |  | `public bool DeleteLogEntry(Guid guid)`
| 0 | `74` |  | `{`
|  | `75` |  | `// Check a logentry exists with the same GUID, if so, remove it.`
| 0 | `76` |  | `var existing = _options.LogEntries.FirstOrDefault(m => m.Guid == guid);`
| 0 | `77` |  | `if (existing != null)`
| 0 | `78` |  | `{`
| 0 | `79` |  | `_options.LogEntries.Remove(existing);`
| 0 | `80` |  | `return true;`
|  | `81` |  | `}`
|  | `82` |  | ``
| 0 | `83` |  | `return false;`
| 0 | `84` |  | `}`
|  | `85` |  | `}`
|  | `86` |  | `}`

# Methods/Properties

.ctor(WireMock.Settings.IFluentMockServerSettings)
InitAdmin()
SaveStaticMappings(System.String)
ReadStaticMappings(System.String)
WatchStaticMappings(System.String)
ReadStaticMappingAndAddOrUpdate(System.String)
InitProxyAndRecord(WireMock.Settings.IFluentMockServerSettings)
ProxyAndRecordAsync()
ToMapping(WireMock.RequestMessage,WireMock.ResponseMessage,System.String[])
SettingsGet(WireMock.RequestMessage)
SettingsUpdate(WireMock.RequestMessage)
MappingGet(WireMock.RequestMessage)
MappingPut(WireMock.RequestMessage)
MappingDelete(WireMock.RequestMessage)
MappingsSave(WireMock.RequestMessage)
SaveMappingToFile(WireMock.Mapping,System.String)
SanitizeFileName(System.String,System.Char)
MappingsGet(WireMock.RequestMessage)
MappingsPost(WireMock.RequestMessage)
DeserializeAndAddOrUpdateMapping(WireMock.Admin.Mappings.MappingModel,System.Nullable`1<System.Guid>,System.String)
MappingsDelete(WireMock.RequestMessage)
RequestGet(WireMock.RequestMessage)
RequestDelete(WireMock.RequestMessage)
RequestsGet(WireMock.RequestMessage)
RequestsDelete(WireMock.RequestMessage)
RequestsFind(WireMock.RequestMessage)
ScenariosGet(WireMock.RequestMessage)
ScenariosReset(WireMock.RequestMessage)
InitRequestBuilder(WireMock.Admin.Mappings.RequestModel,System.Boolean)
InitResponseBuilder(WireMock.Admin.Mappings.ResponseModel)
ToJson(T,System.Boolean)
ToEncoding(WireMock.Admin.Mappings.EncodingModel)
DeserializeObject(WireMock.RequestMessage)
.ctor(WireMock.Settings.IFluentMockServerSettings)
IsStarted()
Ports()
Urls()
Mappings()
Scenarios()
Dispose()
Dispose(System.Boolean)
Start(WireMock.Settings.IFluentMockServerSettings)
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[])
Stop()
AddCatchAllMapping()
Reset()
ResetMappings()
DeleteMapping(System.Guid)
DeleteMapping(System.String)
AddGlobalProcessingDelay(System.TimeSpan)
AllowPartialMapping(System.Boolean)
SetBasicAuthentication(System.String,System.String)
RemoveBasicAuthentication()
SetMaxRequestLogCount(System.Nullable`1<System.Int32>)
SetRequestLogExpirationDuration(System.Nullable`1<System.Int32>)
ResetScenarios()
Given(WireMock.Matchers.Request.IRequestMatcher)
RegisterMapping(WireMock.Mapping)
add_LogEntriesChanged(System.Collections.Specialized.NotifyCollectionChangedEventHandler)
remove_LogEntriesChanged(System.Collections.Specialized.NotifyCollectionChangedEventHandler)
LogEntries()
FindLogEntries(WireMock.Matchers.Request.IRequestMatcher[])
ResetLogEntries()
DeleteLogEntry(System.Guid)