Support Microsoft.AspNetCore for net 4.6.1 and up (#185)

* net451

* tests : net462

* fixed tests

* fix tests

* readme

* Code review

* LocalFileSystemHandlerTests

* refactor
This commit is contained in:
Stef Heyenrath
2018-08-17 18:52:29 +02:00
committed by GitHub
parent 01d6dce62d
commit b57d118c3d
69 changed files with 842 additions and 2032 deletions

View File

@@ -1,4 +1,4 @@
#if NETSTANDARD
#if USE_ASPNETCORE
using System;
using System.Collections.Generic;
using System.Linq;
@@ -107,9 +107,15 @@ namespace WireMock.Owin
IsStarted = true;
#if NETSTANDARD1_3
_logger.Info("WireMock.Net server using netstandard1.3");
#elif NETSTANDARD2_0
_logger.Info("WireMock.Net server using netstandard2.0");
#elif NET46
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
#endif
#if NETSTANDARD1_3
_host.Run(_cts.Token);
#else
_logger.Info("WireMock.Net server using netstandard2.0");
_host.RunAsync(_cts.Token).Wait();
#endif
}
@@ -132,7 +138,7 @@ namespace WireMock.Owin
#if NETSTANDARD1_3
return Task.FromResult(true);
#else
return _host.WaitForShutdownAsync();
return _host.StopAsync();
#endif
}
}

View File

@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
#if !NETSTANDARD
#if !USE_ASPNETCORE
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
@@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Http;
namespace WireMock.Owin
{
#if !NETSTANDARD
#if !USE_ASPNETCORE
internal class GlobalExceptionMiddleware : OwinMiddleware
#else
internal class GlobalExceptionMiddleware
@@ -17,7 +17,7 @@ namespace WireMock.Owin
{
private readonly WireMockMiddlewareOptions _options;
#if !NETSTANDARD
#if !USE_ASPNETCORE
public GlobalExceptionMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next)
{
_options = options;
@@ -30,13 +30,13 @@ namespace WireMock.Owin
}
#endif
#if NETSTANDARD
#if USE_ASPNETCORE
public RequestDelegate Next { get; }
#endif
private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
#if !NETSTANDARD
#if !USE_ASPNETCORE
public override async Task Invoke(IOwinContext ctx)
#else
public async Task Invoke(HttpContext ctx)

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WireMock.Util;
#if !NETSTANDARD
#if !USE_ASPNETCORE
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
@@ -23,14 +23,14 @@ namespace WireMock.Owin
/// <param name="request"></param>
/// <returns></returns>
public async Task<RequestMessage> MapAsync(
#if !NETSTANDARD
#if !USE_ASPNETCORE
IOwinRequest request
#else
HttpRequest request
#endif
)
{
#if !NETSTANDARD
#if !USE_ASPNETCORE
var urldetails = UrlUtils.Parse(request.Uri, request.PathBase);
string clientIP = request.RemoteIpAddress;
#else

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json;
using WireMock.Http;
using WireMock.Util;
#if !NETSTANDARD
#if !USE_ASPNETCORE
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
@@ -24,7 +24,7 @@ namespace WireMock.Owin
private readonly Encoding _utf8NoBom = new UTF8Encoding(false);
// https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
#if !NETSTANDARD
#if !USE_ASPNETCORE
private static readonly IDictionary<string, Action<IOwinResponse, WireMockList<string>>> ResponseHeadersToFix = new Dictionary<string, Action<IOwinResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
#else
private static readonly IDictionary<string, Action<HttpResponse, WireMockList<string>>> ResponseHeadersToFix = new Dictionary<string, Action<HttpResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
@@ -33,7 +33,7 @@ namespace WireMock.Owin
};
private void SetResponseHeaders(ResponseMessage responseMessage
#if !NETSTANDARD
#if !USE_ASPNETCORE
, IOwinResponse response
#else
, HttpResponse response
@@ -49,7 +49,7 @@ namespace WireMock.Owin
}
else
{
#if !NETSTANDARD
#if !USE_ASPNETCORE
// For non-NETSTANDARD, check if this response header can be added (#148)
if (!WebHeaderCollection.IsRestricted(pair.Key, true))
{
@@ -69,7 +69,7 @@ namespace WireMock.Owin
/// <param name="responseMessage"></param>
/// <param name="response"></param>
public async Task MapAsync(ResponseMessage responseMessage
#if !NETSTANDARD
#if !USE_ASPNETCORE
, IOwinResponse response
#else
, HttpResponse response

View File

@@ -1,4 +1,4 @@
#if !NETSTANDARD
#if !USE_ASPNETCORE
using JetBrains.Annotations;
using Microsoft.Owin.Hosting;
using Owin;
@@ -65,9 +65,9 @@ namespace WireMock.Owin
private void StartServers()
{
#if NET46
_logger.Info("WireMock.Net server using .net 4.6.x or higher");
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
#else
_logger.Info("WireMock.Net server using .net 4.5.x or higher");
_logger.Info("WireMock.Net server using .net 4.5.x");
#endif
var servers = new List<IDisposable>();

View File

@@ -9,7 +9,7 @@ using WireMock.Util;
using Newtonsoft.Json;
using WireMock.Http;
using WireMock.Serialization;
#if !NETSTANDARD
#if !USE_ASPNETCORE
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
@@ -17,7 +17,7 @@ using Microsoft.AspNetCore.Http;
namespace WireMock.Owin
{
#if !NETSTANDARD
#if !USE_ASPNETCORE
internal class WireMockMiddleware : OwinMiddleware
#else
internal class WireMockMiddleware
@@ -29,7 +29,7 @@ namespace WireMock.Owin
private readonly OwinRequestMapper _requestMapper = new OwinRequestMapper();
private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
#if !NETSTANDARD
#if !USE_ASPNETCORE
public WireMockMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next)
{
_options = options;
@@ -41,7 +41,7 @@ namespace WireMock.Owin
}
#endif
#if !NETSTANDARD
#if !USE_ASPNETCORE
public override async Task Invoke(IOwinContext ctx)
#else
public async Task Invoke(HttpContext ctx)

View File

@@ -4,7 +4,7 @@ using System.Collections.ObjectModel;
using WireMock.Logging;
using WireMock.Matchers;
using WireMock.Util;
#if !NETSTANDARD
#if !USE_ASPNETCORE
using Owin;
#else
using Microsoft.AspNetCore.Builder;
@@ -32,7 +32,7 @@ namespace WireMock.Owin
public int? MaxRequestLogCount { get; set; }
#if !NETSTANDARD
#if !USE_ASPNETCORE
public Action<IAppBuilder> PreWireMockMiddlewareInit { get; set; }
public Action<IAppBuilder> PostWireMockMiddlewareInit { get; set; }