diff --git a/src/WireMock.Net.Logic/WireMock.Net.Logic.csproj b/src/WireMock.Net.Logic/WireMock.Net.Logic.csproj deleted file mode 100644 index 55867969..00000000 --- a/src/WireMock.Net.Logic/WireMock.Net.Logic.csproj +++ /dev/null @@ -1,46 +0,0 @@ - - - - WireMock.Net.Logic - Stef Heyenrath - net45;netstandard1.3 - true - WireMock.Net.Logic - full - ../WireMock.Net-Logo.ico - 1.0.2.0 - WireMock - - - - NETSTANDARD - - - - - All - - - - - - - - - - - - - - - - - - - 4.3.0 - - - - - - \ No newline at end of file diff --git a/src/WireMock.Net.Middleware/FluentMockServerSettings.cs b/src/WireMock.Net.Middleware/FluentMockServerSettings.cs deleted file mode 100644 index 685bcdc3..00000000 --- a/src/WireMock.Net.Middleware/FluentMockServerSettings.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace WireMock.Net -{ - /// - /// WireMockSettings - /// - public class WireMockSettings - { - /// - /// Gets or sets the port. - /// - /// - /// The port. - /// - public int? Port { get; set; } - - /// - /// Gets or sets the use SSL. - /// - /// - /// The use SSL. - /// - // ReSharper disable once InconsistentNaming - public bool? UseSSL { get; set; } - - /// - /// Gets or sets the start admin interface. - /// - /// - /// The start admin interface. - /// - public bool? StartAdminInterface { get; set; } - - /// - /// Gets or sets the read static mappings. - /// - /// - /// The read static mappings. - /// - public bool? ReadStaticMappings { get; set; } - - /// - /// Gets or sets the urls. - /// - /// - /// The urls. - /// - public string[] Urls { get; set; } - } -} \ No newline at end of file diff --git a/src/WireMock.Net.Middleware/WireMock.Net.Middleware.csproj b/src/WireMock.Net.Middleware/WireMock.Net.Middleware.csproj deleted file mode 100644 index 77b22a32..00000000 --- a/src/WireMock.Net.Middleware/WireMock.Net.Middleware.csproj +++ /dev/null @@ -1,60 +0,0 @@ - - - - WireMock.Net Owin Middleware. - 1.0.0.0 - WireMock.Net - Stef Heyenrath - net45;netstandard1.3 - true - WireMock.Net.Middleware - WireMock.Net.Middleware - tdd;mock;http;wiremock;test;server;unittest - Initial version - https://raw.githubusercontent.com/StefH/WireMock.Net/master/WireMock.Net-Logo.png - https://github.com/StefH/WireMock.Net - https://raw.githubusercontent.com/StefH/WireMock.Net/master/LICENSE - git - https://github.com/StefH/WireMock.Net - True - full - ../WireMock.Net-Logo.ico - WireMock - - - - NETSTANDARD - - - - - - - - - All - - - - - - - - - - - - - - - - - - - 4.3.0 - - - - - - \ No newline at end of file diff --git a/src/WireMock.Net.Middleware/WireMockMiddleware.cs b/src/WireMock.Net.Middleware/WireMockMiddleware.cs deleted file mode 100644 index 23971949..00000000 --- a/src/WireMock.Net.Middleware/WireMockMiddleware.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using System.Collections; -using System.Threading.Tasks; -using WireMock.Logging; -using WireMock.Matchers.Request; -using System.Linq; -#if NETSTANDARD -using Microsoft.AspNetCore.Http; -#else -using Microsoft.Owin; -#endif - -namespace WireMock.Owin -{ -#if NETSTANDARD - internal class WireMockMiddleware -#else - internal class WireMockMiddleware : OwinMiddleware -#endif - { - private static readonly Task CompletedTask = Task.FromResult(false); - private readonly WireMockMiddlewareOptions _options; - - private readonly OwinRequestMapper _requestMapper = new OwinRequestMapper(); - private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper(); - -#if NETSTANDARD - public WireMockMiddleware(RequestDelegate next, WireMockMiddlewareOptions options) - { - _options = options; - } -#else - public WireMockMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next) - { - _options = options; - } -#endif - -#if NETSTANDARD - public async Task Invoke(HttpContext ctx) -#else - public override async Task Invoke(IOwinContext ctx) -#endif - { - if (_options.RequestProcessingDelay > TimeSpan.Zero) - { - await Task.Delay(_options.RequestProcessingDelay.Value); - // Thread.Sleep(_options.RequestProcessingDelay.Value); - } - - var request = await _requestMapper.MapAsync(ctx.Request); - - ResponseMessage response = null; - Mapping targetMapping = null; - RequestMatchResult requestMatchResult = null; - try - { - var mappings = _options.Mappings - .Select(m => new - { - Mapping = m, - MatchResult = m.IsRequestHandled(request) - }) - .ToList(); - - if (_options.AllowPartialMapping) - { - var partialMappings = mappings - .Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdminInterface) - .OrderBy(m => m.MatchResult) - .ThenBy(m => m.Mapping.Priority) - .ToList(); - - var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0); - - targetMapping = bestPartialMatch?.Mapping; - requestMatchResult = bestPartialMatch?.MatchResult; - } - else - { - var perfectMatch = mappings - .OrderBy(m => m.Mapping.Priority) - .FirstOrDefault(m => m.MatchResult.IsPerfectMatch); - - targetMapping = perfectMatch?.Mapping; - requestMatchResult = perfectMatch?.MatchResult; - } - - if (targetMapping == null) - { - response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }; - return; - } - - if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null) - { - string authorization; - bool present = request.Headers.TryGetValue("Authorization", out authorization); - if (!present || _options.AuthorizationMatcher.IsMatch(authorization) < 1.0) - { - response = new ResponseMessage { StatusCode = 401 }; - return; - } - } - - response = await targetMapping.ResponseTo(request); - } - catch (Exception ex) - { - response = new ResponseMessage { StatusCode = 500, Body = ex.ToString() }; - } - finally - { - var log = new LogEntry - { - Guid = Guid.NewGuid(), - RequestMessage = request, - ResponseMessage = response, - MappingGuid = targetMapping?.Guid, - MappingTitle = targetMapping?.Title, - RequestMatchResult = requestMatchResult - }; - - LogRequest(log); - - await _responseMapper.MapAsync(response, ctx.Response); - } - - await CompletedTask; - } - - /// - /// The log request. - /// - /// The request. - private void LogRequest(LogEntry entry) - { - lock (((ICollection)_options.LogEntries).SyncRoot) - { - _options.LogEntries.Add(entry); - } - } - } -} \ No newline at end of file