mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 23:41:19 +02:00
remove IOwin
This commit is contained in:
@@ -11,7 +11,7 @@ using WireMock.Util;
|
|||||||
|
|
||||||
namespace WireMock.Owin;
|
namespace WireMock.Owin;
|
||||||
|
|
||||||
internal partial class AspNetCoreSelfHost : IOwinSelfHost
|
internal partial class AspNetCoreSelfHost
|
||||||
{
|
{
|
||||||
private readonly CancellationTokenSource _cts = new();
|
private readonly CancellationTokenSource _cts = new();
|
||||||
private readonly IWireMockMiddlewareOptions _wireMockMiddlewareOptions;
|
private readonly IWireMockMiddlewareOptions _wireMockMiddlewareOptions;
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
// Copyright © WireMock.Net
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace WireMock.Owin;
|
|
||||||
|
|
||||||
interface IOwinSelfHost
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a value indicating whether this server is started.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// <c>true</c> if this server is started; otherwise, <c>false</c>.
|
|
||||||
/// </value>
|
|
||||||
bool IsStarted { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the urls.
|
|
||||||
/// </summary>
|
|
||||||
List<string> Urls { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the ports.
|
|
||||||
/// </summary>
|
|
||||||
List<int> Ports { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The exception occurred when the host is running.
|
|
||||||
/// </summary>
|
|
||||||
Exception? RunningException { get; }
|
|
||||||
|
|
||||||
Task StartAsync();
|
|
||||||
|
|
||||||
Task StopAsync();
|
|
||||||
}
|
|
||||||
@@ -39,7 +39,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
private const int ServerStartDelayInMs = 100;
|
private const int ServerStartDelayInMs = 100;
|
||||||
|
|
||||||
private readonly WireMockServerSettings _settings;
|
private readonly WireMockServerSettings _settings;
|
||||||
private readonly IOwinSelfHost? _httpServer;
|
private readonly AspNetCoreSelfHost? _httpServer;
|
||||||
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||||
private readonly MappingConverter _mappingConverter;
|
private readonly MappingConverter _mappingConverter;
|
||||||
private readonly MatcherMapper _matcherMapper;
|
private readonly MatcherMapper _matcherMapper;
|
||||||
|
|||||||
@@ -1,45 +1,36 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.Owin.Mappers;
|
using WireMock.Owin.Mappers;
|
||||||
using Xunit;
|
|
||||||
#if NET452
|
|
||||||
using IContext = Microsoft.Owin.IOwinContext;
|
|
||||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
|
||||||
#else
|
|
||||||
using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
|
||||||
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Owin
|
namespace WireMock.Net.Tests.Owin;
|
||||||
|
|
||||||
|
public class GlobalExceptionMiddlewareTests
|
||||||
{
|
{
|
||||||
public class GlobalExceptionMiddlewareTests
|
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
|
||||||
|
private readonly Mock<IOwinResponseMapper> _responseMapperMock;
|
||||||
|
|
||||||
|
private readonly GlobalExceptionMiddleware _sut;
|
||||||
|
|
||||||
|
public GlobalExceptionMiddlewareTests()
|
||||||
{
|
{
|
||||||
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
|
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||||
private readonly Mock<IOwinResponseMapper> _responseMapperMock;
|
_optionsMock.SetupAllProperties();
|
||||||
|
|
||||||
private readonly GlobalExceptionMiddleware _sut;
|
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||||
|
_responseMapperMock.SetupAllProperties();
|
||||||
|
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
||||||
|
|
||||||
public GlobalExceptionMiddlewareTests()
|
_sut = new GlobalExceptionMiddleware(null, _optionsMock.Object, _responseMapperMock.Object);
|
||||||
{
|
}
|
||||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
|
||||||
_optionsMock.SetupAllProperties();
|
|
||||||
|
|
||||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
[Fact]
|
||||||
_responseMapperMock.SetupAllProperties();
|
public void GlobalExceptionMiddleware_Invoke_NullAsNext_DoesNotInvokeNextAndDoesNotThrow()
|
||||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<IResponse>())).Returns(Task.FromResult(true));
|
{
|
||||||
|
// Act
|
||||||
_sut = new GlobalExceptionMiddleware(null, _optionsMock.Object, _responseMapperMock.Object);
|
Check.ThatCode(() => _sut.Invoke(null)).DoesNotThrow();
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void GlobalExceptionMiddleware_Invoke_NullAsNext_DoesNotInvokeNextAndDoesNotThrow()
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
Check.ThatCode(() => _sut.Invoke(null)).DoesNotThrow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,14 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.Owin.Mappers;
|
using WireMock.Owin.Mappers;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
@@ -21,21 +17,12 @@ using WireMock.Handlers;
|
|||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
using WireMock.Owin.ActivityTracing;
|
using WireMock.Owin.ActivityTracing;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
#endif
|
#endif
|
||||||
#if NET452
|
|
||||||
using Microsoft.Owin;
|
|
||||||
using IContext = Microsoft.Owin.IOwinContext;
|
|
||||||
using IRequest = Microsoft.Owin.IOwinRequest;
|
|
||||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
|
||||||
#else
|
|
||||||
using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
|
||||||
using IRequest = Microsoft.AspNetCore.Http.HttpRequest;
|
|
||||||
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Owin;
|
namespace WireMock.Net.Tests.Owin;
|
||||||
|
|
||||||
@@ -51,7 +38,7 @@ public class WireMockMiddlewareTests
|
|||||||
private readonly Mock<IMappingMatcher> _matcherMock;
|
private readonly Mock<IMappingMatcher> _matcherMock;
|
||||||
private readonly Mock<IMapping> _mappingMock;
|
private readonly Mock<IMapping> _mappingMock;
|
||||||
private readonly Mock<IRequestMatchResult> _requestMatchResultMock;
|
private readonly Mock<IRequestMatchResult> _requestMatchResultMock;
|
||||||
private readonly Mock<IContext> _contextMock;
|
private readonly Mock<HttpContext> _contextMock;
|
||||||
|
|
||||||
private readonly WireMockMiddleware _sut;
|
private readonly WireMockMiddleware _sut;
|
||||||
|
|
||||||
@@ -76,13 +63,13 @@ public class WireMockMiddlewareTests
|
|||||||
|
|
||||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||||
_responseMapperMock.SetupAllProperties();
|
_responseMapperMock.SetupAllProperties();
|
||||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<IResponse>())).Returns(Task.FromResult(true));
|
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
||||||
|
|
||||||
_matcherMock = new Mock<IMappingMatcher>();
|
_matcherMock = new Mock<IMappingMatcher>();
|
||||||
_matcherMock.SetupAllProperties();
|
_matcherMock.SetupAllProperties();
|
||||||
// _matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((new MappingMatcherResult(), new MappingMatcherResult()));
|
// _matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((new MappingMatcherResult(), new MappingMatcherResult()));
|
||||||
|
|
||||||
_contextMock = new Mock<IContext>();
|
_contextMock = new Mock<HttpContext>();
|
||||||
_contextMock.SetupGet(c => c.Items).Returns(new Dictionary<object, object?>());
|
_contextMock.SetupGet(c => c.Items).Returns(new Dictionary<object, object?>());
|
||||||
|
|
||||||
_mappingMock = new Mock<IMapping>();
|
_mappingMock = new Mock<IMapping>();
|
||||||
@@ -111,7 +98,7 @@ public class WireMockMiddlewareTests
|
|||||||
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||||
|
|
||||||
Expression<Func<ResponseMessage, bool>> match = r => (int)r.StatusCode! == 404 && ((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found";
|
Expression<Func<ResponseMessage, bool>> match = r => (int)r.StatusCode! == 404 && ((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found";
|
||||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -129,7 +116,7 @@ public class WireMockMiddlewareTests
|
|||||||
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||||
|
|
||||||
Expression<Func<ResponseMessage, bool>> match = r => (int)r.StatusCode! == 404 && ((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found";
|
Expression<Func<ResponseMessage, bool>> match = r => (int)r.StatusCode! == 404 && ((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found";
|
||||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
fileSystemHandlerMock.Verify(f => f.WriteUnmatchedRequest("98fae52e-76df-47d9-876f-2ee32e931d9b.LogEntry.json", It.IsAny<string>()));
|
fileSystemHandlerMock.Verify(f => f.WriteUnmatchedRequest("98fae52e-76df-47d9-876f-2ee32e931d9b.LogEntry.json", It.IsAny<string>()));
|
||||||
@@ -156,7 +143,7 @@ public class WireMockMiddlewareTests
|
|||||||
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||||
|
|
||||||
Expression<Func<ResponseMessage, bool>> match = r => (int?)r.StatusCode == 401;
|
Expression<Func<ResponseMessage, bool>> match = r => (int?)r.StatusCode == 401;
|
||||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -179,7 +166,7 @@ public class WireMockMiddlewareTests
|
|||||||
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||||
|
|
||||||
Expression<Func<ResponseMessage, bool>> match = r => (int?)r.StatusCode == 401;
|
Expression<Func<ResponseMessage, bool>> match = r => (int?)r.StatusCode == 401;
|
||||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<IResponse>()), Times.Once);
|
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user