mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-11-16 13:51:04 +01:00
Fix DateTime in Response (#1514)
* Fix DateTime in Response * // Set the DateTime from the Response to the current DateTime --------- Co-authored-by: Stef Heyenrath <stef.heyenrath@apg.nl>
This commit is contained in:
1 parent
dd762f218b
commit
cb4503b1a6
15 files changed
+92
-23
No files matched your search
@@ -0,0 +1,29 @@
|
||||
// Copyright © WireMock.Net
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using WireMock.Net.Testcontainers.Utils;
|
||||
|
||||
namespace WireMock.Net.Tests.Facts;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class RunOnDockerFact : FactAttribute
|
||||
{
|
||||
public RunOnDockerFact(
|
||||
[CallerFilePath] string? sourceFilePath = null,
|
||||
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||
{
|
||||
|
||||
OSPlatform currentPlatform;
|
||||
try
|
||||
{
|
||||
currentPlatform = TestcontainersUtils.GetImageOSAsync.Value.Result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Skip = $"Only run test when Docker is installed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -15,7 +15,19 @@ public sealed class RunOnDockerPlatformFact : FactAttribute
|
||||
[CallerFilePath] string? sourceFilePath = null,
|
||||
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||
{
|
||||
if (TestcontainersUtils.GetImageOSAsync.Value.Result != OSPlatform.Create(platform))
|
||||
|
||||
OSPlatform currentPlatform;
|
||||
try
|
||||
{
|
||||
currentPlatform = TestcontainersUtils.GetImageOSAsync.Value.Result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Skip = $"Only run test when Docker is installed.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPlatform != OSPlatform.Create(platform))
|
||||
{
|
||||
Skip = $"Only run test when Docker OS Platform {platform} is used.";
|
||||
}
|
||||
|
||||
@@ -106,6 +106,15 @@ public class WireMockMiddlewareTests
|
||||
[Fact]
|
||||
public async Task WireMockMiddleware_Invoke_NoMatch()
|
||||
{
|
||||
// Arrange
|
||||
var inititalDateTime = new DateTime(2027, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
var responseDateTime = new DateTime(2027, 1, 1, 0, 0, 42, DateTimeKind.Utc);
|
||||
|
||||
_dateTimeUtilsMock.Reset();
|
||||
_dateTimeUtilsMock.SetupSequence(d => d.UtcNow)
|
||||
.Returns(inititalDateTime)
|
||||
.Returns(responseDateTime);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
|
||||
@@ -115,7 +124,7 @@ public class WireMockMiddlewareTests
|
||||
Expression<Func<ResponseMessage, bool>> match = r =>
|
||||
(int)r.StatusCode! == 404 &&
|
||||
((StatusModel)r.BodyData!.BodyAsJson!).Status == "No matching mapping found" &&
|
||||
r.DateTime == UtcNow;
|
||||
r.DateTime == responseDateTime;
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.Is(match), It.IsAny<HttpResponse>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TestcontainersTests(ITestOutputHelper testOutputHelper)
|
||||
TimestampFormat = "yyy-MM-dd HH:mm:ss.fff"
|
||||
});
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_And_StartAsync_and_StopAsync()
|
||||
{
|
||||
// Act
|
||||
@@ -57,7 +57,7 @@ public class TestcontainersTests(ITestOutputHelper testOutputHelper)
|
||||
await StopAsync(wireMockContainer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_WithImage_And_StartAsync_and_StopAsync()
|
||||
{
|
||||
// Arrange
|
||||
@@ -83,7 +83,7 @@ public class TestcontainersTests(ITestOutputHelper testOutputHelper)
|
||||
await StopAsync(wireMockContainer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_WithImageAsText_And_StartAsync_and_StopAsync()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -10,6 +10,7 @@ using Meziantou.Extensions.Logging.Xunit.v3;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WireMock.Constants;
|
||||
using WireMock.Net.Testcontainers;
|
||||
using WireMock.Net.Tests.Facts;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Net.Tests.Testcontainers;
|
||||
@@ -25,7 +26,7 @@ public class TestcontainersTestsGrpc(ITestOutputHelper testOutputHelper)
|
||||
TimestampFormat = "yyy-MM-dd HH:mm:ss.fff"
|
||||
});
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_Grpc_TestPortsAndUrls1()
|
||||
{
|
||||
// Arrange
|
||||
@@ -82,7 +83,7 @@ public class TestcontainersTestsGrpc(ITestOutputHelper testOutputHelper)
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_Grpc_TestPortsAndUrls2()
|
||||
{
|
||||
// Arrange
|
||||
@@ -136,7 +137,7 @@ public class TestcontainersTestsGrpc(ITestOutputHelper testOutputHelper)
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_Grpc_ProtoDefinitionFromJson_UsingGrpcGeneratedClient()
|
||||
{
|
||||
var wireMockContainer = await Given_WireMockContainerIsStartedForHttpAndGrpcAsync();
|
||||
@@ -150,7 +151,7 @@ public class TestcontainersTestsGrpc(ITestOutputHelper testOutputHelper)
|
||||
await StopAsync(wireMockContainer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_Grpc_ProtoDefinitionAtServerLevel_UsingGrpcGeneratedClient()
|
||||
{
|
||||
var wireMockContainer = await Given_WireMockContainerWithProtoDefinitionAtServerLevelIsStartedForHttpAndGrpcAsync();
|
||||
@@ -164,7 +165,7 @@ public class TestcontainersTestsGrpc(ITestOutputHelper testOutputHelper)
|
||||
await StopAsync(wireMockContainer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[RunOnDockerFact]
|
||||
public async Task WireMockContainer_Build_Grpc_ProtoDefinitionAtServerLevel_UsingGrpcGeneratedClient_AndWithWatchStaticMappings()
|
||||
{
|
||||
var wireMockContainer = await Given_WireMockContainerWithProtoDefinitionAtServerLevelWithWatchStaticMappingsIsStartedForHttpAndGrpcAsync();
|
||||
|
||||
@@ -18,6 +18,7 @@ using WireMock.Util;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
[Collection(nameof(WireMockServerProxyTests))]
|
||||
public class WireMockServerProxyTests
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
@@ -45,6 +45,4 @@ public class WireMockServerProxy2Tests
|
||||
server.Dispose();
|
||||
serverAsProxy.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user