Fix request storing when RequestLogExpirationDuration is set [bug] (#1455)

* Fix response timestamp

* Extracted new interface to own file
This commit is contained in:
Peter Benko
2026-05-11 10:28:38 +02:00
committed by GitHub
parent 4bb378bdce
commit 67acdcf1d3
16 changed files with 126 additions and 80 deletions
@@ -3,6 +3,7 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Net;
using Microsoft.AspNetCore.Http;
using Moq;
using WireMock.Admin.Mappings;
@@ -38,6 +39,7 @@ public class WireMockMiddlewareTests
private readonly Mock<HttpContext> _contextMock;
private readonly Mock<IGuidUtils> _guidUtilsMock;
private readonly Mock<IDateTimeUtils> _dateTimeUtilsMock;
private readonly IResponseMessageBuilder _responseMessageBuilderMock;
private readonly WireMockMiddleware _sut;
@@ -51,6 +53,8 @@ public class WireMockMiddlewareTests
_dateTimeUtilsMock = new Mock<IDateTimeUtils>();
_dateTimeUtilsMock.Setup(d => d.UtcNow).Returns(UtcNow);
_responseMessageBuilderMock = new ResponseMessageBuilder(_dateTimeUtilsMock.Object);
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
_optionsMock.SetupAllProperties();
_optionsMock.Setup(o => o.Mappings).Returns(_mappings);
@@ -90,7 +94,8 @@ public class WireMockMiddlewareTests
_matcherMock.Object,
wireMockMiddlewareLoggerMock.Object,
_guidUtilsMock.Object,
_dateTimeUtilsMock.Object
_dateTimeUtilsMock.Object,
_responseMessageBuilderMock
);
}
@@ -103,7 +108,10 @@ public class WireMockMiddlewareTests
// Assert and Verify
_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" &&
r.DateTime == UtcNow;
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
}