Methods/Properties
diff --git a/report/WireMock.Net_FluentMockServer.htm b/report/WireMock.Net_FluentMockServer.htm
index 7996f2b6..a88d195b 100644
--- a/report/WireMock.Net_FluentMockServer.htm
+++ b/report/WireMock.Net_FluentMockServer.htm
@@ -16,12 +16,12 @@
| 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% |
|---|
+
| Covered lines: | 200 |
|---|
+
| Uncovered lines: | 423 |
|---|
+
| Coverable lines: | 623 |
|---|
+
| Total lines: | 1180 |
|---|
+
| Line coverage: | 32.1% |
|---|
+
| Branch coverage: | 29.2% |
Metrics
@@ -58,7 +58,7 @@
| Map(...) | 15 | 1024 | 52.63 | 47.62 |
| ToJson(...) | 1 | 0 | 0 | 0 |
| ToEncoding(...) | 3 | 2 | 100 | 66.67 |
-
| .ctor(...) | 15 | 512 | 80 | 57.89 |
+
| .ctor(...) | 15 | 512 | 77.78 | 57.89 |
| .cctor() | 1 | 0 | 100 | 100 |
| FindLogEntries(...) | 8 | 2 | 100 | 100 |
| Start(...) | 1 | 0 | 0 | 0 |
@@ -80,8 +80,6 @@
| SetBasicAuthentication(...) | 1 | 0 | 0 | 0 |
| Given(...) | 1 | 0 | 100 | 100 |
| RegisterMapping(...) | 2 | 0 | 100 | 100 |
-
| LogRequest(...) | 2 | 0 | 100 | 100 |
-
| HandleRequestAsync() | 35 | 16384 | 68.63 | 66.67 |
File(s)
@@ -213,8 +211,8 @@
| | 0 | 122 | | { |
| | 0 | 123 | | var model = new SettingsModel |
| | 0 | 124 | | { |
-
| | 0 | 125 | | AllowPartialMapping = _allowPartialMapping, |
-
| | 0 | 126 | | GlobalProcessingDelay = _requestProcessingDelay?.Milliseconds |
+
| | 0 | 125 | | AllowPartialMapping = _options.AllowPartialMapping, |
+
| | 0 | 126 | | GlobalProcessingDelay = _options.RequestProcessingDelay?.Milliseconds |
| | 0 | 127 | | }; |
| | | 128 | | |
| | 0 | 129 | | return ToJson(model); |
@@ -225,10 +223,10 @@
| | 0 | 134 | | var settings = JsonConvert.DeserializeObject<SettingsModel>(requestMessage.Body); |
| | | 135 | | |
| | 0 | 136 | | if (settings.AllowPartialMapping != null) |
-
| | 0 | 137 | | _allowPartialMapping = settings.AllowPartialMapping.Value; |
+
| | 0 | 137 | | _options.AllowPartialMapping = settings.AllowPartialMapping.Value; |
| | | 138 | | |
| | 0 | 139 | | if (settings.GlobalProcessingDelay != null) |
-
| | 0 | 140 | | _requestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value); |
+
| | 0 | 140 | | _options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value); |
| | | 141 | | |
| | 0 | 142 | | return new ResponseMessage { Body = "Settings updated" }; |
| | 0 | 143 | | } |
@@ -420,7 +418,7 @@
| | 0 | 329 | | { |
| | 0 | 330 | | DateTime = logEntry.RequestMessage.DateTime, |
| | 0 | 331 | | Path = logEntry.RequestMessage.Path, |
-
| | 0 | 332 | | AbsoleteUrl = logEntry.RequestMessage.Url, |
+
| | 0 | 332 | | AbsoluteUrl = logEntry.RequestMessage.Url, |
| | 0 | 333 | | Query = logEntry.RequestMessage.Query, |
| | 0 | 334 | | Method = logEntry.RequestMessage.Method, |
| | 0 | 335 | | Body = logEntry.RequestMessage.Body, |
@@ -772,8 +770,8 @@
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Collections.ObjectModel; |
| | | 5 | | using System.Linq; |
-
| | | 6 | | using System.Net; |
-
| | | 7 | | using System.Text; |
+
| | | 6 | | using System.Text; |
+
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using JetBrains.Annotations; |
| | | 10 | | using WireMock.Http; |
@@ -782,7 +780,7 @@
| | | 13 | | using WireMock.Matchers.Request; |
| | | 14 | | using WireMock.RequestBuilders; |
| | | 15 | | using WireMock.Validation; |
-
| | | 16 | | using System.Threading; |
+
| | | 16 | | using WireMock.Owin; |
| | | 17 | | |
| | | 18 | | namespace WireMock.Server |
| | | 19 | | { |
@@ -791,511 +789,493 @@
| | | 22 | | /// </summary> |
| | | 23 | | public partial class FluentMockServer : IDisposable |
| | | 24 | | { |
-
| | | 25 | | private readonly TinyHttpServer _httpServer; |
+
| | | 25 | | private readonly IOwinSelfHost _httpServer; |
| | | 26 | | |
-
| | 18 | 27 | | private IList<Mapping> _mappings = new List<Mapping>(); |
+
| | 18 | 27 | | private readonly object _syncRoot = new object(); |
| | | 28 | | |
-
| | 18 | 29 | | private readonly IList<LogEntry> _logEntries = new List<LogEntry>(); |
+
| | 18 | 29 | | private readonly WireMockMiddlewareOptions _options = new WireMockMiddlewareOptions(); |
| | | 30 | | |
-
| | 18 | 31 | | private readonly HttpListenerRequestMapper _requestMapper = new HttpListenerRequestMapper(); |
-
| | | 32 | | |
-
| | 18 | 33 | | private readonly HttpListenerResponseMapper _responseMapper = new HttpListenerResponseMapper(); |
-
| | | 34 | | |
-
| | 18 | 35 | | 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> |
+
| | | 31 | | /// <summary> |
+
| | | 32 | | /// Gets the ports. |
+
| | | 33 | | /// </summary> |
+
| | | 34 | | /// <value> |
+
| | | 35 | | /// The ports. |
+
| | | 36 | | /// </value> |
+
| | | 37 | | [PublicAPI] |
+
| | 13 | 38 | | public List<int> Ports { get; } |
+
| | | 39 | | |
+
| | | 40 | | /// <summary> |
+
| | | 41 | | /// Gets the urls. |
+
| | | 42 | | /// </summary> |
+
| | | 43 | | [PublicAPI] |
+
| | 18 | 44 | | public string[] Urls { get; } |
+
| | | 45 | | |
+
| | | 46 | | /// <summary> |
+
| | | 47 | | /// Gets the request logs. |
+
| | | 48 | | /// </summary> |
| | | 49 | | [PublicAPI] |
-
| | 13 | 50 | | public List<int> Ports { get; } |
-
| | | 51 | | |
-
| | | 52 | | /// <summary> |
-
| | | 53 | | /// Gets the urls. |
-
| | | 54 | | /// </summary> |
-
| | | 55 | | [PublicAPI] |
-
| | 18 | 56 | | public string[] Urls { get; } |
-
| | | 57 | | |
-
| | | 58 | | /// <summary> |
-
| | | 59 | | /// Gets the request logs. |
-
| | | 60 | | /// </summary> |
-
| | | 61 | | [PublicAPI] |
-
| | | 62 | | public IEnumerable<LogEntry> LogEntries |
-
| | | 63 | | { |
-
| | | 64 | | get |
-
| | 3 | 65 | | { |
-
| | 3 | 66 | | lock (((ICollection)_logEntries).SyncRoot) |
-
| | 3 | 67 | | { |
-
| | 3 | 68 | | return new ReadOnlyCollection<LogEntry>(_logEntries); |
-
| | | 69 | | } |
-
| | 3 | 70 | | } |
-
| | | 71 | | } |
+
| | | 50 | | public IEnumerable<LogEntry> LogEntries |
+
| | | 51 | | { |
+
| | | 52 | | get |
+
| | 3 | 53 | | { |
+
| | 3 | 54 | | lock (((ICollection)_options.LogEntries).SyncRoot) |
+
| | 3 | 55 | | { |
+
| | 3 | 56 | | return new ReadOnlyCollection<LogEntry>(_options.LogEntries); |
+
| | | 57 | | } |
+
| | 3 | 58 | | } |
+
| | | 59 | | } |
+
| | | 60 | | |
+
| | | 61 | | /// <summary> |
+
| | | 62 | | /// The search log-entries based on matchers. |
+
| | | 63 | | /// </summary> |
+
| | | 64 | | /// <param name="matchers">The matchers.</param> |
+
| | | 65 | | /// <returns>The <see cref="IEnumerable"/>.</returns> |
+
| | | 66 | | [PublicAPI] |
+
| | | 67 | | public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers) |
+
| | 1 | 68 | | { |
+
| | 1 | 69 | | lock (((ICollection)_options.LogEntries).SyncRoot) |
+
| | 1 | 70 | | { |
+
| | 1 | 71 | | var results = new Dictionary<LogEntry, RequestMatchResult>(); |
| | | 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) |
-
| | 1 | 80 | | { |
-
| | 1 | 81 | | lock (((ICollection)_logEntries).SyncRoot) |
-
| | 1 | 82 | | { |
-
| | 1 | 83 | | var results = new Dictionary<LogEntry, RequestMatchResult>(); |
+
| | 7 | 73 | | foreach (var log in _options.LogEntries) |
+
| | 2 | 74 | | { |
+
| | 2 | 75 | | var requestMatchResult = new RequestMatchResult(); |
+
| | 10 | 76 | | foreach (var matcher in matchers) |
+
| | 2 | 77 | | { |
+
| | 2 | 78 | | matcher.GetMatchingScore(log.RequestMessage, requestMatchResult); |
+
| | 2 | 79 | | } |
+
| | | 80 | | |
+
| | 2 | 81 | | if (requestMatchResult.AverageTotalScore > 0.99) |
+
| | 1 | 82 | | results.Add(log, requestMatchResult); |
+
| | 2 | 83 | | } |
| | | 84 | | |
-
| | 7 | 85 | | foreach (var log in _logEntries) |
-
| | 2 | 86 | | { |
-
| | 2 | 87 | | var requestMatchResult = new RequestMatchResult(); |
-
| | 10 | 88 | | foreach (var matcher in matchers) |
-
| | 2 | 89 | | { |
-
| | 2 | 90 | | matcher.GetMatchingScore(log.RequestMessage, requestMatchResult); |
-
| | 2 | 91 | | } |
-
| | | 92 | | |
-
| | 2 | 93 | | if (requestMatchResult.AverageTotalScore > 0.99) |
-
| | 1 | 94 | | results.Add(log, requestMatchResult); |
-
| | 2 | 95 | | } |
-
| | | 96 | | |
-
| | 3 | 97 | | return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList()); |
-
| | | 98 | | } |
-
| | 1 | 99 | | } |
-
| | | 100 | | |
-
| | | 101 | | /// <summary> |
-
| | | 102 | | /// Gets the mappings. |
-
| | | 103 | | /// </summary> |
-
| | | 104 | | [PublicAPI] |
-
| | | 105 | | public IEnumerable<Mapping> Mappings |
-
| | | 106 | | { |
-
| | | 107 | | get |
-
| | 7 | 108 | | { |
-
| | 7 | 109 | | lock (((ICollection)_mappings).SyncRoot) |
-
| | 7 | 110 | | { |
-
| | 7 | 111 | | return new ReadOnlyCollection<Mapping>(_mappings); |
-
| | | 112 | | } |
-
| | 7 | 113 | | } |
-
| | | 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) |
-
| | 0 | 123 | | { |
-
| | 0 | 124 | | Check.NotNull(settings, nameof(settings)); |
-
| | | 125 | | |
-
| | 0 | 126 | | return new FluentMockServer(settings); |
-
| | 0 | 127 | | } |
-
| | | 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) |
-
| | 16 | 137 | | { |
-
| | 16 | 138 | | return new FluentMockServer(new FluentMockServerSettings |
-
| | 16 | 139 | | { |
-
| | 16 | 140 | | Port = port, |
-
| | 16 | 141 | | UseSSL = ssl |
-
| | 16 | 142 | | }); |
-
| | 16 | 143 | | } |
-
| | | 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) |
-
| | 2 | 152 | | { |
-
| | 2 | 153 | | Check.NotEmpty(urls, nameof(urls)); |
-
| | | 154 | | |
-
| | 2 | 155 | | return new FluentMockServer(new FluentMockServerSettings |
-
| | 2 | 156 | | { |
-
| | 2 | 157 | | Urls = urls |
-
| | 2 | 158 | | }); |
-
| | 2 | 159 | | } |
-
| | | 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) |
-
| | 0 | 169 | | { |
-
| | 0 | 170 | | return new FluentMockServer(new FluentMockServerSettings |
-
| | 0 | 171 | | { |
-
| | 0 | 172 | | Port = port, |
-
| | 0 | 173 | | UseSSL = ssl, |
-
| | 0 | 174 | | StartAdminInterface = true |
-
| | 0 | 175 | | }); |
-
| | 0 | 176 | | } |
-
| | | 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) |
-
| | 0 | 185 | | { |
-
| | 0 | 186 | | Check.NotEmpty(urls, nameof(urls)); |
-
| | | 187 | | |
-
| | 0 | 188 | | return new FluentMockServer(new FluentMockServerSettings |
-
| | 0 | 189 | | { |
-
| | 0 | 190 | | Urls = urls, |
-
| | 0 | 191 | | StartAdminInterface = true |
-
| | 0 | 192 | | }); |
-
| | 0 | 193 | | } |
-
| | | 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) |
-
| | 0 | 202 | | { |
-
| | 0 | 203 | | Check.NotEmpty(urls, nameof(urls)); |
-
| | | 204 | | |
-
| | 0 | 205 | | return new FluentMockServer(new FluentMockServerSettings |
-
| | 0 | 206 | | { |
-
| | 0 | 207 | | Urls = urls, |
-
| | 0 | 208 | | StartAdminInterface = true, |
-
| | 0 | 209 | | ReadStaticMappings = true |
-
| | 0 | 210 | | }); |
-
| | 0 | 211 | | } |
+
| | 3 | 85 | | return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList()); |
+
| | | 86 | | } |
+
| | 1 | 87 | | } |
+
| | | 88 | | |
+
| | | 89 | | /// <summary> |
+
| | | 90 | | /// Gets the mappings. |
+
| | | 91 | | /// </summary> |
+
| | | 92 | | [PublicAPI] |
+
| | | 93 | | public IEnumerable<Mapping> Mappings |
+
| | | 94 | | { |
+
| | | 95 | | get |
+
| | 7 | 96 | | { |
+
| | 7 | 97 | | lock (((ICollection)_options.Mappings).SyncRoot) |
+
| | 7 | 98 | | { |
+
| | 7 | 99 | | return new ReadOnlyCollection<Mapping>(_options.Mappings); |
+
| | | 100 | | } |
+
| | 7 | 101 | | } |
+
| | | 102 | | } |
+
| | | 103 | | |
+
| | | 104 | | /// <summary> |
+
| | | 105 | | /// Starts the specified settings. |
+
| | | 106 | | /// </summary> |
+
| | | 107 | | /// <param name="settings">The FluentMockServerSettings.</param> |
+
| | | 108 | | /// <returns>The <see cref="FluentMockServer"/>.</returns> |
+
| | | 109 | | [PublicAPI] |
+
| | | 110 | | public static FluentMockServer Start(FluentMockServerSettings settings) |
+
| | 0 | 111 | | { |
+
| | 0 | 112 | | Check.NotNull(settings, nameof(settings)); |
+
| | | 113 | | |
+
| | 0 | 114 | | return new FluentMockServer(settings); |
+
| | 0 | 115 | | } |
+
| | | 116 | | |
+
| | | 117 | | /// <summary> |
+
| | | 118 | | /// Start this FluentMockServer. |
+
| | | 119 | | /// </summary> |
+
| | | 120 | | /// <param name="port">The port.</param> |
+
| | | 121 | | /// <param name="ssl">The SSL support.</param> |
+
| | | 122 | | /// <returns>The <see cref="FluentMockServer"/>.</returns> |
+
| | | 123 | | [PublicAPI] |
+
| | | 124 | | public static FluentMockServer Start([CanBeNull] int? port = 0, bool ssl = false) |
+
| | 16 | 125 | | { |
+
| | 16 | 126 | | return new FluentMockServer(new FluentMockServerSettings |
+
| | 16 | 127 | | { |
+
| | 16 | 128 | | Port = port, |
+
| | 16 | 129 | | UseSSL = ssl |
+
| | 16 | 130 | | }); |
+
| | 16 | 131 | | } |
+
| | | 132 | | |
+
| | | 133 | | /// <summary> |
+
| | | 134 | | /// Start this FluentMockServer. |
+
| | | 135 | | /// </summary> |
+
| | | 136 | | /// <param name="urls">The urls to listen on.</param> |
+
| | | 137 | | /// <returns>The <see cref="FluentMockServer"/>.</returns> |
+
| | | 138 | | [PublicAPI] |
+
| | | 139 | | public static FluentMockServer Start(params string[] urls) |
+
| | 2 | 140 | | { |
+
| | 2 | 141 | | Check.NotEmpty(urls, nameof(urls)); |
+
| | | 142 | | |
+
| | 2 | 143 | | return new FluentMockServer(new FluentMockServerSettings |
+
| | 2 | 144 | | { |
+
| | 2 | 145 | | Urls = urls |
+
| | 2 | 146 | | }); |
+
| | 2 | 147 | | } |
+
| | | 148 | | |
+
| | | 149 | | /// <summary> |
+
| | | 150 | | /// Start this FluentMockServer with the admin interface. |
+
| | | 151 | | /// </summary> |
+
| | | 152 | | /// <param name="port">The port.</param> |
+
| | | 153 | | /// <param name="ssl">The SSL support.</param> |
+
| | | 154 | | /// <returns>The <see cref="FluentMockServer"/>.</returns> |
+
| | | 155 | | [PublicAPI] |
+
| | | 156 | | public static FluentMockServer StartWithAdminInterface(int? port = 0, bool ssl = false) |
+
| | 0 | 157 | | { |
+
| | 0 | 158 | | return new FluentMockServer(new FluentMockServerSettings |
+
| | 0 | 159 | | { |
+
| | 0 | 160 | | Port = port, |
+
| | 0 | 161 | | UseSSL = ssl, |
+
| | 0 | 162 | | StartAdminInterface = true |
+
| | 0 | 163 | | }); |
+
| | 0 | 164 | | } |
+
| | | 165 | | |
+
| | | 166 | | /// <summary> |
+
| | | 167 | | /// Start this FluentMockServer with the admin interface. |
+
| | | 168 | | /// </summary> |
+
| | | 169 | | /// <param name="urls">The urls.</param> |
+
| | | 170 | | /// <returns>The <see cref="FluentMockServer"/>.</returns> |
+
| | | 171 | | [PublicAPI] |
+
| | | 172 | | public static FluentMockServer StartWithAdminInterface(params string[] urls) |
+
| | 0 | 173 | | { |
+
| | 0 | 174 | | Check.NotEmpty(urls, nameof(urls)); |
+
| | | 175 | | |
+
| | 0 | 176 | | return new FluentMockServer(new FluentMockServerSettings |
+
| | 0 | 177 | | { |
+
| | 0 | 178 | | Urls = urls, |
+
| | 0 | 179 | | StartAdminInterface = true |
+
| | 0 | 180 | | }); |
+
| | 0 | 181 | | } |
+
| | | 182 | | |
+
| | | 183 | | /// <summary> |
+
| | | 184 | | /// Start this FluentMockServer with the admin interface and read static mappings. |
+
| | | 185 | | /// </summary> |
+
| | | 186 | | /// <param name="urls">The urls.</param> |
+
| | | 187 | | /// <returns>The <see cref="FluentMockServer"/>.</returns> |
+
| | | 188 | | [PublicAPI] |
+
| | | 189 | | public static FluentMockServer StartWithAdminInterfaceAndReadStaticMappings(params string[] urls) |
+
| | 0 | 190 | | { |
+
| | 0 | 191 | | Check.NotEmpty(urls, nameof(urls)); |
+
| | | 192 | | |
+
| | 0 | 193 | | return new FluentMockServer(new FluentMockServerSettings |
+
| | 0 | 194 | | { |
+
| | 0 | 195 | | Urls = urls, |
+
| | 0 | 196 | | StartAdminInterface = true, |
+
| | 0 | 197 | | ReadStaticMappings = true |
+
| | 0 | 198 | | }); |
+
| | 0 | 199 | | } |
+
| | | 200 | | |
+
| | 18 | 201 | | private FluentMockServer(FluentMockServerSettings settings) |
+
| | 18 | 202 | | { |
+
| | 18 | 203 | | if (settings.Urls != null) |
+
| | 2 | 204 | | { |
+
| | 2 | 205 | | Urls = settings.Urls; |
+
| | 2 | 206 | | } |
+
| | | 207 | | else |
+
| | 16 | 208 | | { |
+
| | 16 | 209 | | int port = settings.Port > 0 ? settings.Port.Value : PortUtil.FindFreeTcpPort(); |
+
| | 16 | 210 | | Urls = new[] { (settings.UseSSL == true ? "https" : "http") + "://localhost:" + port + "/" }; |
+
| | 16 | 211 | | } |
| | | 212 | | |
-
| | 18 | 213 | | private FluentMockServer(FluentMockServerSettings settings) |
-
| | 18 | 214 | | { |
-
| | 18 | 215 | | if (settings.Urls != null) |
-
| | 2 | 216 | | { |
-
| | 2 | 217 | | Urls = settings.Urls; |
-
| | 2 | 218 | | } |
-
| | | 219 | | else |
-
| | 16 | 220 | | { |
-
| | 16 | 221 | | int port = settings.Port > 0 ? settings.Port.Value : PortUtil.FindFreeTcpPort(); |
-
| | 16 | 222 | | Urls = new[] { (settings.UseSSL == true ? "https" : "http") + "://localhost:" + port + "/" }; |
-
| | 16 | 223 | | } |
-
| | | 224 | | |
-
| | 18 | 225 | | _httpServer = new TinyHttpServer(HandleRequestAsync, Urls); |
-
| | 18 | 226 | | Ports = _httpServer.Ports; |
-
| | | 227 | | |
-
| | 18 | 228 | | _httpServer.Start(); |
-
| | | 229 | | |
-
| | 18 | 230 | | if (settings.StartAdminInterface == true) |
-
| | 0 | 231 | | { |
-
| | 0 | 232 | | InitAdmin(); |
-
| | 0 | 233 | | } |
-
| | | 234 | | |
-
| | 18 | 235 | | if (settings.ReadStaticMappings == true) |
-
| | 0 | 236 | | { |
-
| | 0 | 237 | | ReadStaticMappings(); |
-
| | 0 | 238 | | } |
-
| | 18 | 239 | | } |
-
| | | 240 | | |
-
| | | 241 | | /// <summary> |
-
| | | 242 | | /// Adds the catch all mapping. |
-
| | | 243 | | /// </summary> |
-
| | | 244 | | [PublicAPI] |
-
| | | 245 | | public void AddCatchAllMapping() |
-
| | 0 | 246 | | { |
-
| | 0 | 247 | | Given(Request.Create().WithPath("/*").UsingAnyVerb()) |
-
| | 0 | 248 | | .WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05")) |
-
| | 0 | 249 | | .AtPriority(1000) |
-
| | 0 | 250 | | .RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No m |
-
| | 0 | 251 | | } |
+
| | | 213 | | #if NET45 |
+
| | 18 | 214 | | _httpServer = new OwinSelfHost(_options, Urls); |
+
| | | 215 | | #else |
+
| | | 216 | | _httpServer = new AspNetCoreSelfHost(_options, Urls); |
+
| | | 217 | | #endif |
+
| | 18 | 218 | | Ports = _httpServer.Ports; |
+
| | | 219 | | |
+
| | 18 | 220 | | _httpServer.StartAsync(); |
+
| | | 221 | | |
+
| | 18 | 222 | | if (settings.StartAdminInterface == true) |
+
| | 0 | 223 | | { |
+
| | 0 | 224 | | InitAdmin(); |
+
| | 0 | 225 | | } |
+
| | | 226 | | |
+
| | 18 | 227 | | if (settings.ReadStaticMappings == true) |
+
| | 0 | 228 | | { |
+
| | 0 | 229 | | ReadStaticMappings(); |
+
| | 0 | 230 | | } |
+
| | 18 | 231 | | } |
+
| | | 232 | | |
+
| | | 233 | | /// <summary> |
+
| | | 234 | | /// Adds the catch all mapping. |
+
| | | 235 | | /// </summary> |
+
| | | 236 | | [PublicAPI] |
+
| | | 237 | | public void AddCatchAllMapping() |
+
| | 0 | 238 | | { |
+
| | 0 | 239 | | Given(Request.Create().WithPath("/*").UsingAnyVerb()) |
+
| | 0 | 240 | | .WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05")) |
+
| | 0 | 241 | | .AtPriority(1000) |
+
| | 0 | 242 | | .RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No m |
+
| | 0 | 243 | | } |
+
| | | 244 | | |
+
| | | 245 | | /// <summary> |
+
| | | 246 | | /// Stop this server. |
+
| | | 247 | | /// </summary> |
+
| | | 248 | | [PublicAPI] |
+
| | | 249 | | public void Stop() |
+
| | 18 | 250 | | { |
+
| | 18 | 251 | | _httpServer?.StopAsync(); |
| | | 252 | | |
-
| | | 253 | | /// <summary> |
-
| | | 254 | | /// Stop this server. |
-
| | | 255 | | /// </summary> |
-
| | | 256 | | [PublicAPI] |
-
| | | 257 | | public void Stop() |
-
| | 18 | 258 | | { |
-
| | 18 | 259 | | _httpServer?.Stop(); |
-
| | 18 | 260 | | } |
-
| | | 261 | | |
-
| | | 262 | | /// <summary> |
-
| | | 263 | | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
-
| | | 264 | | /// </summary> |
-
| | | 265 | | public void Dispose() |
-
| | 0 | 266 | | { |
-
| | 0 | 267 | | if (_httpServer != null && _httpServer.IsStarted) |
-
| | 0 | 268 | | { |
-
| | 0 | 269 | | _httpServer.Stop(); |
-
| | 0 | 270 | | } |
-
| | 0 | 271 | | } |
-
| | | 272 | | |
-
| | | 273 | | /// <summary> |
-
| | | 274 | | /// Resets LogEntries and Mappings. |
-
| | | 275 | | /// </summary> |
-
| | | 276 | | [PublicAPI] |
-
| | | 277 | | public void Reset() |
-
| | 0 | 278 | | { |
-
| | 0 | 279 | | ResetLogEntries(); |
-
| | | 280 | | |
-
| | 0 | 281 | | ResetMappings(); |
-
| | 0 | 282 | | } |
-
| | | 283 | | |
-
| | | 284 | | /// <summary> |
-
| | | 285 | | /// Resets the LogEntries. |
-
| | | 286 | | /// </summary> |
-
| | | 287 | | [PublicAPI] |
-
| | | 288 | | public void ResetLogEntries() |
-
| | 1 | 289 | | { |
-
| | 1 | 290 | | lock (((ICollection)_logEntries).SyncRoot) |
-
| | 1 | 291 | | { |
-
| | 1 | 292 | | _logEntries.Clear(); |
-
| | 1 | 293 | | } |
-
| | 1 | 294 | | } |
-
| | | 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) |
-
| | 0 | 302 | | { |
-
| | 0 | 303 | | lock (((ICollection)_logEntries).SyncRoot) |
-
| | 0 | 304 | | { |
-
| | | 305 | | // Check a logentry exists with the same GUID, if so, remove it. |
-
| | 0 | 306 | | var existing = _logEntries.FirstOrDefault(m => m.Guid == guid); |
-
| | 0 | 307 | | if (existing != null) |
-
| | 0 | 308 | | { |
-
| | 0 | 309 | | _logEntries.Remove(existing); |
-
| | 0 | 310 | | return true; |
-
| | | 311 | | } |
-
| | | 312 | | |
-
| | 0 | 313 | | return false; |
-
| | | 314 | | } |
-
| | 0 | 315 | | } |
-
| | | 316 | | |
-
| | | 317 | | /// <summary> |
-
| | | 318 | | /// Resets the Mappings. |
-
| | | 319 | | /// </summary> |
-
| | | 320 | | [PublicAPI] |
-
| | | 321 | | public void ResetMappings() |
-
| | 1 | 322 | | { |
-
| | 1 | 323 | | lock (((ICollection)_mappings).SyncRoot) |
-
| | 1 | 324 | | { |
-
| | 2 | 325 | | _mappings = _mappings.Where(m => m.Provider is DynamicResponseProvider).ToList(); |
-
| | 1 | 326 | | } |
-
| | 1 | 327 | | } |
-
| | | 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) |
-
| | 17 | 335 | | { |
-
| | 17 | 336 | | lock (((ICollection)_mappings).SyncRoot) |
-
| | 17 | 337 | | { |
-
| | | 338 | | // Check a mapping exists with the same GUID, if so, remove it. |
-
| | 22 | 339 | | var existingMapping = _mappings.FirstOrDefault(m => m.Guid == guid); |
-
| | 17 | 340 | | if (existingMapping != null) |
-
| | 1 | 341 | | { |
-
| | 1 | 342 | | _mappings.Remove(existingMapping); |
-
| | 1 | 343 | | return true; |
-
| | | 344 | | } |
-
| | | 345 | | |
-
| | 16 | 346 | | return false; |
-
| | | 347 | | } |
-
| | 17 | 348 | | } |
-
| | | 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) |
-
| | 1 | 358 | | { |
-
| | 1 | 359 | | lock (_syncRoot) |
-
| | 1 | 360 | | { |
-
| | 1 | 361 | | _requestProcessingDelay = delay; |
-
| | 1 | 362 | | } |
-
| | 1 | 363 | | } |
-
| | | 364 | | |
-
| | | 365 | | /// <summary> |
-
| | | 366 | | /// Allows the partial mapping. |
-
| | | 367 | | /// </summary> |
-
| | | 368 | | [PublicAPI] |
-
| | | 369 | | public void AllowPartialMapping() |
-
| | 0 | 370 | | { |
-
| | 0 | 371 | | lock (_syncRoot) |
-
| | 0 | 372 | | { |
-
| | 0 | 373 | | _allowPartialMapping = true; |
-
| | 0 | 374 | | } |
-
| | 0 | 375 | | } |
-
| | | 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) |
-
| | 0 | 384 | | { |
-
| | 0 | 385 | | Check.NotNull(username, nameof(username)); |
-
| | 0 | 386 | | Check.NotNull(password, nameof(password)); |
-
| | | 387 | | |
-
| | 0 | 388 | | string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + p |
-
| | 0 | 389 | | _authorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$"); |
-
| | 0 | 390 | | } |
-
| | | 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) |
-
| | 17 | 399 | | { |
-
| | 17 | 400 | | return new RespondWithAProvider(RegisterMapping, requestMatcher); |
-
| | 17 | 401 | | } |
-
| | | 402 | | |
-
| | | 403 | | /// <summary> |
-
| | | 404 | | /// The register mapping. |
-
| | | 405 | | /// </summary> |
-
| | | 406 | | /// <param name="mapping"> |
-
| | | 407 | | /// The mapping. |
-
| | | 408 | | /// </param> |
-
| | | 409 | | private void RegisterMapping(Mapping mapping) |
-
| | 17 | 410 | | { |
-
| | 17 | 411 | | lock (((ICollection)_mappings).SyncRoot) |
-
| | 17 | 412 | | { |
-
| | | 413 | | // Check a mapping exists with the same GUID, if so, remove it first. |
-
| | 17 | 414 | | DeleteMapping(mapping.Guid); |
-
| | | 415 | | |
-
| | 17 | 416 | | _mappings.Add(mapping); |
-
| | 17 | 417 | | } |
-
| | 17 | 418 | | } |
-
| | | 419 | | |
-
| | | 420 | | /// <summary> |
-
| | | 421 | | /// The log request. |
-
| | | 422 | | /// </summary> |
-
| | | 423 | | /// <param name="entry">The request.</param> |
-
| | | 424 | | private void LogRequest(LogEntry entry) |
-
| | 13 | 425 | | { |
-
| | 13 | 426 | | lock (((ICollection)_logEntries).SyncRoot) |
-
| | 13 | 427 | | { |
-
| | 13 | 428 | | _logEntries.Add(entry); |
-
| | 13 | 429 | | } |
-
| | 13 | 430 | | } |
+
| | | 253 | | //while (_httpServer != null && _httpServer.IsStarted) |
+
| | | 254 | | //{ |
+
| | | 255 | | // Task.Delay(999).Wait(); |
+
| | | 256 | | //} |
+
| | 18 | 257 | | } |
+
| | | 258 | | |
+
| | | 259 | | /// <summary> |
+
| | | 260 | | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
+
| | | 261 | | /// </summary> |
+
| | | 262 | | public void Dispose() |
+
| | 0 | 263 | | { |
+
| | 0 | 264 | | if (_httpServer != null && _httpServer.IsStarted) |
+
| | 0 | 265 | | { |
+
| | 0 | 266 | | _httpServer.StopAsync(); |
+
| | | 267 | | |
+
| | | 268 | | //while (_httpServer != null && _httpServer.IsStarted) |
+
| | | 269 | | //{ |
+
| | | 270 | | // Task.Delay(999).Wait(); |
+
| | | 271 | | //} |
+
| | 0 | 272 | | } |
+
| | 0 | 273 | | } |
+
| | | 274 | | |
+
| | | 275 | | /// <summary> |
+
| | | 276 | | /// Resets LogEntries and Mappings. |
+
| | | 277 | | /// </summary> |
+
| | | 278 | | [PublicAPI] |
+
| | | 279 | | public void Reset() |
+
| | 0 | 280 | | { |
+
| | 0 | 281 | | ResetLogEntries(); |
+
| | | 282 | | |
+
| | 0 | 283 | | ResetMappings(); |
+
| | 0 | 284 | | } |
+
| | | 285 | | |
+
| | | 286 | | /// <summary> |
+
| | | 287 | | /// Resets the LogEntries. |
+
| | | 288 | | /// </summary> |
+
| | | 289 | | [PublicAPI] |
+
| | | 290 | | public void ResetLogEntries() |
+
| | 1 | 291 | | { |
+
| | 1 | 292 | | lock (((ICollection)_options.LogEntries).SyncRoot) |
+
| | 1 | 293 | | { |
+
| | 1 | 294 | | _options.LogEntries.Clear(); |
+
| | 1 | 295 | | } |
+
| | 1 | 296 | | } |
+
| | | 297 | | |
+
| | | 298 | | /// <summary> |
+
| | | 299 | | /// Deletes the mapping. |
+
| | | 300 | | /// </summary> |
+
| | | 301 | | /// <param name="guid">The unique identifier.</param> |
+
| | | 302 | | [PublicAPI] |
+
| | | 303 | | public bool DeleteLogEntry(Guid guid) |
+
| | 0 | 304 | | { |
+
| | 0 | 305 | | lock (((ICollection)_options.LogEntries).SyncRoot) |
+
| | 0 | 306 | | { |
+
| | | 307 | | // Check a logentry exists with the same GUID, if so, remove it. |
+
| | 0 | 308 | | var existing = _options.LogEntries.FirstOrDefault(m => m.Guid == guid); |
+
| | 0 | 309 | | if (existing != null) |
+
| | 0 | 310 | | { |
+
| | 0 | 311 | | _options.LogEntries.Remove(existing); |
+
| | 0 | 312 | | return true; |
+
| | | 313 | | } |
+
| | | 314 | | |
+
| | 0 | 315 | | return false; |
+
| | | 316 | | } |
+
| | 0 | 317 | | } |
+
| | | 318 | | |
+
| | | 319 | | /// <summary> |
+
| | | 320 | | /// Resets the Mappings. |
+
| | | 321 | | /// </summary> |
+
| | | 322 | | [PublicAPI] |
+
| | | 323 | | public void ResetMappings() |
+
| | 1 | 324 | | { |
+
| | 1 | 325 | | lock (((ICollection)_options.Mappings).SyncRoot) |
+
| | 1 | 326 | | { |
+
| | 2 | 327 | | _options.Mappings = _options.Mappings.Where(m => m.Provider is DynamicResponseProvider).ToList(); |
+
| | 1 | 328 | | } |
+
| | 1 | 329 | | } |
+
| | | 330 | | |
+
| | | 331 | | /// <summary> |
+
| | | 332 | | /// Deletes the mapping. |
+
| | | 333 | | /// </summary> |
+
| | | 334 | | /// <param name="guid">The unique identifier.</param> |
+
| | | 335 | | [PublicAPI] |
+
| | | 336 | | public bool DeleteMapping(Guid guid) |
+
| | 17 | 337 | | { |
+
| | 17 | 338 | | lock (((ICollection)_options.Mappings).SyncRoot) |
+
| | 17 | 339 | | { |
+
| | | 340 | | // Check a mapping exists with the same GUID, if so, remove it. |
+
| | 22 | 341 | | var existingMapping = _options.Mappings.FirstOrDefault(m => m.Guid == guid); |
+
| | 17 | 342 | | if (existingMapping != null) |
+
| | 1 | 343 | | { |
+
| | 1 | 344 | | _options.Mappings.Remove(existingMapping); |
+
| | 1 | 345 | | return true; |
+
| | | 346 | | } |
+
| | | 347 | | |
+
| | 16 | 348 | | return false; |
+
| | | 349 | | } |
+
| | 17 | 350 | | } |
+
| | | 351 | | |
+
| | | 352 | | /// <summary> |
+
| | | 353 | | /// The add request processing delay. |
+
| | | 354 | | /// </summary> |
+
| | | 355 | | /// <param name="delay"> |
+
| | | 356 | | /// The delay. |
+
| | | 357 | | /// </param> |
+
| | | 358 | | [PublicAPI] |
+
| | | 359 | | public void AddGlobalProcessingDelay(TimeSpan delay) |
+
| | 1 | 360 | | { |
+
| | 1 | 361 | | lock (_syncRoot) |
+
| | 1 | 362 | | { |
+
| | 1 | 363 | | _options.RequestProcessingDelay = delay; |
+
| | 1 | 364 | | } |
+
| | 1 | 365 | | } |
+
| | | 366 | | |
+
| | | 367 | | /// <summary> |
+
| | | 368 | | /// Allows the partial mapping. |
+
| | | 369 | | /// </summary> |
+
| | | 370 | | [PublicAPI] |
+
| | | 371 | | public void AllowPartialMapping() |
+
| | 0 | 372 | | { |
+
| | 0 | 373 | | lock (_syncRoot) |
+
| | 0 | 374 | | { |
+
| | 0 | 375 | | _options.AllowPartialMapping = true; |
+
| | 0 | 376 | | } |
+
| | 0 | 377 | | } |
+
| | | 378 | | |
+
| | | 379 | | /// <summary> |
+
| | | 380 | | /// Sets the basic authentication. |
+
| | | 381 | | /// </summary> |
+
| | | 382 | | /// <param name="username">The username.</param> |
+
| | | 383 | | /// <param name="password">The password.</param> |
+
| | | 384 | | [PublicAPI] |
+
| | | 385 | | public void SetBasicAuthentication([NotNull] string username, [NotNull] string password) |
+
| | 0 | 386 | | { |
+
| | 0 | 387 | | Check.NotNull(username, nameof(username)); |
+
| | 0 | 388 | | Check.NotNull(password, nameof(password)); |
+
| | | 389 | | |
+
| | 0 | 390 | | string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + p |
+
| | 0 | 391 | | _options.AuthorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$"); |
+
| | 0 | 392 | | } |
+
| | | 393 | | |
+
| | | 394 | | /// <summary> |
+
| | | 395 | | /// The given. |
+
| | | 396 | | /// </summary> |
+
| | | 397 | | /// <param name="requestMatcher">The request matcher.</param> |
+
| | | 398 | | /// <returns>The <see cref="IRespondWithAProvider"/>.</returns> |
+
| | | 399 | | [PublicAPI] |
+
| | | 400 | | public IRespondWithAProvider Given(IRequestMatcher requestMatcher) |
+
| | 17 | 401 | | { |
+
| | 17 | 402 | | return new RespondWithAProvider(RegisterMapping, requestMatcher); |
+
| | 17 | 403 | | } |
+
| | | 404 | | |
+
| | | 405 | | /// <summary> |
+
| | | 406 | | /// The register mapping. |
+
| | | 407 | | /// </summary> |
+
| | | 408 | | /// <param name="mapping"> |
+
| | | 409 | | /// The mapping. |
+
| | | 410 | | /// </param> |
+
| | | 411 | | private void RegisterMapping(Mapping mapping) |
+
| | 17 | 412 | | { |
+
| | 17 | 413 | | lock (((ICollection)_options.Mappings).SyncRoot) |
+
| | 17 | 414 | | { |
+
| | | 415 | | // Check a mapping exists with the same GUID, if so, remove it first. |
+
| | 17 | 416 | | DeleteMapping(mapping.Guid); |
+
| | | 417 | | |
+
| | 17 | 418 | | _options.Mappings.Add(mapping); |
+
| | 17 | 419 | | } |
+
| | 17 | 420 | | } |
+
| | | 421 | | |
+
| | | 422 | | //private async void HandleRequestOld(IOwinContext ctx) |
+
| | | 423 | | //{ |
+
| | | 424 | | // if (_requestProcessingDelay > TimeSpan.Zero) |
+
| | | 425 | | // { |
+
| | | 426 | | // lock (_syncRoot) |
+
| | | 427 | | // { |
+
| | | 428 | | // Task.Delay(_requestProcessingDelay.Value).Wait(); |
+
| | | 429 | | // } |
+
| | | 430 | | // } |
| | | 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) |
-
| | 13 | 438 | | { |
-
| | 13 | 439 | | if (cancel.IsCancellationRequested) |
-
| | 0 | 440 | | return; |
-
| | | 441 | | |
-
| | 13 | 442 | | if (_requestProcessingDelay > TimeSpan.Zero) |
-
| | 1 | 443 | | { |
-
| | 1 | 444 | | lock (_syncRoot) |
-
| | 1 | 445 | | { |
-
| | 1 | 446 | | Task.Delay(_requestProcessingDelay.Value, cancel).Wait(cancel); |
-
| | 1 | 447 | | } |
-
| | 1 | 448 | | } |
-
| | | 449 | | |
-
| | 13 | 450 | | var request = _requestMapper.Map(ctx.Request); |
-
| | | 451 | | |
-
| | 13 | 452 | | ResponseMessage response = null; |
-
| | 13 | 453 | | Mapping targetMapping = null; |
-
| | 13 | 454 | | RequestMatchResult requestMatchResult = null; |
-
| | | 455 | | try |
-
| | 13 | 456 | | { |
-
| | 13 | 457 | | var mappings = _mappings |
-
| | 23 | 458 | | .Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) }) |
-
| | 13 | 459 | | .ToList(); |
-
| | | 460 | | |
-
| | 13 | 461 | | if (_allowPartialMapping) |
-
| | 0 | 462 | | { |
-
| | 0 | 463 | | var partialMappings = mappings |
-
| | 0 | 464 | | .Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdmin |
-
| | 0 | 465 | | .OrderBy(m => m.MatchResult) |
-
| | 0 | 466 | | .ThenBy(m => m.Mapping.Priority) |
-
| | 0 | 467 | | .ToList(); |
-
| | | 468 | | |
-
| | 0 | 469 | | var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0); |
-
| | | 470 | | |
-
| | 0 | 471 | | targetMapping = bestPartialMatch?.Mapping; |
-
| | 0 | 472 | | requestMatchResult = bestPartialMatch?.MatchResult; |
-
| | 0 | 473 | | } |
-
| | | 474 | | else |
-
| | 13 | 475 | | { |
-
| | 13 | 476 | | var perfectMatch = mappings |
-
| | 23 | 477 | | .OrderBy(m => m.Mapping.Priority) |
-
| | 21 | 478 | | .FirstOrDefault(m => m.MatchResult.IsPerfectMatch); |
-
| | | 479 | | |
-
| | 13 | 480 | | targetMapping = perfectMatch?.Mapping; |
-
| | 13 | 481 | | requestMatchResult = perfectMatch?.MatchResult; |
-
| | 13 | 482 | | } |
-
| | | 483 | | |
-
| | 13 | 484 | | if (targetMapping == null) |
-
| | 6 | 485 | | { |
-
| | 6 | 486 | | response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }; |
-
| | 6 | 487 | | return; |
-
| | | 488 | | } |
-
| | | 489 | | |
-
| | 7 | 490 | | if (targetMapping.IsAdminInterface && _authorizationMatcher != null) |
-
| | 0 | 491 | | { |
-
| | | 492 | | string authorization; |
-
| | 0 | 493 | | bool present = request.Headers.TryGetValue("Authorization", out authorization); |
-
| | 0 | 494 | | if (!present || _authorizationMatcher.IsMatch(authorization) < 1.0) |
-
| | 0 | 495 | | { |
-
| | 0 | 496 | | response = new ResponseMessage { StatusCode = 401 }; |
-
| | 0 | 497 | | return; |
-
| | | 498 | | } |
-
| | 0 | 499 | | } |
+
| | | 432 | | // var request = _requestMapper.MapAsync(ctx.Request); |
+
| | | 433 | | |
+
| | | 434 | | // ResponseMessage response = null; |
+
| | | 435 | | // Mapping targetMapping = null; |
+
| | | 436 | | // RequestMatchResult requestMatchResult = null; |
+
| | | 437 | | // try |
+
| | | 438 | | // { |
+
| | | 439 | | // var mappings = _mappings |
+
| | | 440 | | // .Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) }) |
+
| | | 441 | | // .ToList(); |
+
| | | 442 | | |
+
| | | 443 | | // if (_allowPartialMapping) |
+
| | | 444 | | // { |
+
| | | 445 | | // var partialMappings = mappings |
+
| | | 446 | | // .Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdm |
+
| | | 447 | | // .OrderBy(m => m.MatchResult) |
+
| | | 448 | | // .ThenBy(m => m.Mapping.Priority) |
+
| | | 449 | | // .ToList(); |
+
| | | 450 | | |
+
| | | 451 | | // var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0 |
+
| | | 452 | | |
+
| | | 453 | | // targetMapping = bestPartialMatch?.Mapping; |
+
| | | 454 | | // requestMatchResult = bestPartialMatch?.MatchResult; |
+
| | | 455 | | // } |
+
| | | 456 | | // else |
+
| | | 457 | | // { |
+
| | | 458 | | // var perfectMatch = mappings |
+
| | | 459 | | // .OrderBy(m => m.Mapping.Priority) |
+
| | | 460 | | // .FirstOrDefault(m => m.MatchResult.IsPerfectMatch); |
+
| | | 461 | | |
+
| | | 462 | | // targetMapping = perfectMatch?.Mapping; |
+
| | | 463 | | // requestMatchResult = perfectMatch?.MatchResult; |
+
| | | 464 | | // } |
+
| | | 465 | | |
+
| | | 466 | | // if (targetMapping == null) |
+
| | | 467 | | // { |
+
| | | 468 | | // response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }; |
+
| | | 469 | | // return; |
+
| | | 470 | | // } |
+
| | | 471 | | |
+
| | | 472 | | // if (targetMapping.IsAdminInterface && _authorizationMatcher != null) |
+
| | | 473 | | // { |
+
| | | 474 | | // string authorization; |
+
| | | 475 | | // bool present = request.Headers.TryGetValue("Authorization", out authorization); |
+
| | | 476 | | // if (!present || _authorizationMatcher.IsMatch(authorization) < 1.0) |
+
| | | 477 | | // { |
+
| | | 478 | | // response = new ResponseMessage { StatusCode = 401 }; |
+
| | | 479 | | // return; |
+
| | | 480 | | // } |
+
| | | 481 | | // } |
+
| | | 482 | | |
+
| | | 483 | | // response = await targetMapping.ResponseTo(request); |
+
| | | 484 | | // } |
+
| | | 485 | | // catch (Exception ex) |
+
| | | 486 | | // { |
+
| | | 487 | | // response = new ResponseMessage { StatusCode = 500, Body = ex.ToString() }; |
+
| | | 488 | | // } |
+
| | | 489 | | // finally |
+
| | | 490 | | // { |
+
| | | 491 | | // var log = new LogEntry |
+
| | | 492 | | // { |
+
| | | 493 | | // Guid = Guid.NewGuid(), |
+
| | | 494 | | // RequestMessage = request, |
+
| | | 495 | | // ResponseMessage = response, |
+
| | | 496 | | // MappingGuid = targetMapping?.Guid, |
+
| | | 497 | | // MappingTitle = targetMapping?.Title, |
+
| | | 498 | | // RequestMatchResult = requestMatchResult |
+
| | | 499 | | // }; |
| | | 500 | | |
-
| | 7 | 501 | | response = await targetMapping.ResponseTo(request); |
-
| | 7 | 502 | | } |
-
| | 0 | 503 | | catch (Exception ex) |
-
| | 0 | 504 | | { |
-
| | 0 | 505 | | response = new ResponseMessage { StatusCode = 500, Body = ex.ToString() }; |
-
| | 0 | 506 | | } |
-
| | | 507 | | finally |
-
| | 13 | 508 | | { |
-
| | 13 | 509 | | var log = new LogEntry |
-
| | 13 | 510 | | { |
-
| | 13 | 511 | | Guid = Guid.NewGuid(), |
-
| | 13 | 512 | | RequestMessage = request, |
-
| | 13 | 513 | | ResponseMessage = response, |
-
| | 13 | 514 | | MappingGuid = targetMapping?.Guid, |
-
| | 13 | 515 | | MappingTitle = targetMapping?.Title, |
-
| | 13 | 516 | | RequestMatchResult = requestMatchResult |
-
| | 13 | 517 | | }; |
-
| | | 518 | | |
-
| | 13 | 519 | | LogRequest(log); |
-
| | | 520 | | |
-
| | 13 | 521 | | _responseMapper.Map(response, ctx.Response); |
-
| | 13 | 522 | | ctx.Response.Close(); |
-
| | 13 | 523 | | } |
-
| | 13 | 524 | | } |
-
| | | 525 | | } |
-
| | | 526 | | } |
+
| | | 501 | | // LogRequest(log); |
+
| | | 502 | | |
+
| | | 503 | | // _responseMapper.MapAsync(response, ctx.Response); |
+
| | | 504 | | // ctx.Response.Close(); |
+
| | | 505 | | // } |
+
| | | 506 | | //} |
+
| | | 507 | | } |
+
| | | 508 | | } |
-