This commit is contained in:
Stef Heyenrath
2026-02-28 16:02:22 +01:00
parent d472d158bd
commit 933c8ab0b8
10 changed files with 32 additions and 25 deletions

View File

@@ -45,12 +45,12 @@ public class ProxyAndRecordSettingsModel
/// <summary>
/// Defines a list from headers which will be excluded from the saved mappings.
/// </summary>
public string[] ExcludedHeaders { get; set; }
public string[] ExcludedHeaders { get; set; } = [];
/// <summary>
/// Defines a list of cookies which will be excluded from the saved mappings.
/// </summary>
public string[] ExcludedCookies { get; set; }
public string[] ExcludedCookies { get; set; } = [];
/// <summary>
/// Prefer the Proxy Mapping over the saved Mapping (in case SaveMapping is set to <c>true</c>).

View File

@@ -32,11 +32,6 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<None Remove="../../resources/WireMock.Net-Logo.png" />
<None Include="../../resources/WireMock.Net-LogoAspire.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
</ItemGroup>

View File

@@ -19,7 +19,7 @@ internal class GlobalExceptionMiddleware
_responseMapper = Guard.NotNull(responseMapper);
}
public RequestDelegate? Next { get; }
public RequestDelegate Next { get; }
public Task Invoke(HttpContext ctx)
{
@@ -30,10 +30,7 @@ internal class GlobalExceptionMiddleware
{
try
{
if (Next != null)
{
await Next.Invoke(ctx).ConfigureAwait(false);
}
await Next.Invoke(ctx).ConfigureAwait(false);
}
catch (Exception ex)
{

View File

@@ -1,7 +1,6 @@
// Copyright © WireMock.Net
using System.Diagnostics;
using System.Linq;
using System.Net;
using Microsoft.AspNetCore.Http;
using WireMock.Constants;
@@ -18,7 +17,9 @@ using WireMock.Util;
namespace WireMock.Owin;
internal class WireMockMiddleware(
#pragma warning disable CS9113 // Parameter is unread.
RequestDelegate next,
#pragma warning restore CS9113 // Parameter is unread.
IWireMockMiddlewareOptions options,
IOwinRequestMapper requestMapper,
IOwinResponseMapper responseMapper,

View File

@@ -298,7 +298,7 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
var mappedHeaders = headers?
.ToDictionary(item => item.Key, _ => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern!) ?? [];
if (!string.IsNullOrEmpty(responseContentType))
if (responseContentType != null)
{
mappedHeaders.TryAdd(HeaderContentType, responseContentType);
}

View File

@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
using System;
using WireMock.Models;
using WireMock.Util;
@@ -40,6 +39,6 @@ public class RequestMessageProtoBufMatcher : IRequestMatcher
private MatchResult GetMatchResult(IRequestMessage requestMessage)
{
return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? default;
return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? MatchResult.From(nameof(RequestMessageProtoBufMatcher));
}
}

View File

@@ -582,7 +582,7 @@ public class WireMockAdminApiAssertionsTests : IDisposable
public async Task HaveReceivedACall_FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
{
await _httpClient.GetAsync("", _ct);
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
var clientIP = _server.LogEntries.Last().RequestMessage!.ClientIP;
_adminApi.Should()
.HaveReceivedACall()

View File

@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Moq;
using WireMock.Logging;
using WireMock.Owin;
using WireMock.Owin.Mappers;
@@ -17,20 +18,32 @@ public class GlobalExceptionMiddlewareTests
public GlobalExceptionMiddlewareTests()
{
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
_optionsMock.SetupAllProperties();
_optionsMock.SetupGet(o => o.Logger).Returns(Mock.Of<IWireMockLogger>());
_responseMapperMock = new Mock<IOwinResponseMapper>();
_responseMapperMock.SetupAllProperties();
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
_sut = new GlobalExceptionMiddleware(null, _optionsMock.Object, _responseMapperMock.Object);
_sut = new GlobalExceptionMiddleware(_ => Task.CompletedTask, _optionsMock.Object, _responseMapperMock.Object);
}
[Fact]
public void GlobalExceptionMiddleware_Invoke_NullAsNext_DoesNotInvokeNextAndDoesNotThrow()
public void GlobalExceptionMiddleware_Invoke_ValidNext_ShouldNotThrow()
{
// Act
Action act = () => _sut.Invoke(null);
act.Should().NotThrow();
_sut.Invoke(Mock.Of<HttpContext>());
}
[Fact]
public void GlobalExceptionMiddleware_Invoke_InvalidNext_ShouldCallResponseMapperWith500()
{
// Arrange
var sut = new GlobalExceptionMiddleware(_ => throw new ArgumentException(), _optionsMock.Object, _responseMapperMock.Object);
// Act
sut.Invoke(Mock.Of<HttpContext>());
// Verify
_responseMapperMock.Verify(m => m.MapAsync(It.IsAny<ResponseMessage>(), It.IsAny<HttpResponse>()), Times.Once);
_responseMapperMock.VerifyNoOtherCalls();
}
}

View File

@@ -35,7 +35,7 @@ public class ResponseWithBodyFromFileTests
);
// Act
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content");
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content", _ct);
// Assert
response.Should().Contain("<hello>world</hello>");

View File

@@ -796,7 +796,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
var proxyUri = new Uri($"{sut.Url}/ws/proxy");
await client.ConnectAsync(proxyUri, _ct);
await Task.Delay(500, _ct);
await Task.Delay(250, _ct);
var testData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
@@ -805,6 +805,8 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
var receivedData = await client.ReceiveAsBytesAsync(cancellationToken: _ct);
await Task.Delay(250, _ct);
// Assert
receivedData.Should().BeEquivalentTo(testData, "binary data should be proxied and echoed back");