mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Matching DateTime values in json body #696
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DannyBoyIT on GitHub (Jun 2, 2025).
Originally assigned to: @StefH on GitHub.
I can't for the love of coding figure out how to successfully match specific requests that contain DateTime objects in the body.
Our setup:
We have a Web API that uses .NET 9. We have underlying dependencies to other Web APIs that I am trying to mock/fake with WireMock.
In my client code:
In my Custom Endpoint setup:
The two different
jsonStringvariables have identical values in both places. When my client makes the call though it gets back a404if I set therequestBody. If I do not set therequestBodyI get an answer back from WireMock as expected.What am I missing?
@StefH commented on GitHub (Jun 2, 2025):
@DannyBoyIT
Did you check this page?
https://github.com/wiremock/WireMock.Net/wiki/Request-Matching-Tips
@DannyBoyIT commented on GitHub (Jun 3, 2025):
No, I didn't see that before but when I try to execute the request to
http://localhost:62137/__admin/requests(the WireMock instance while running my integration tests) I get a 404 with Body"Status": "No matching mapping found"@StefH commented on GitHub (Jun 3, 2025):
In order to access the
__admin, you need to start the WireMock.Net server with the admin interface enabled.https://github.com/wiremock/WireMock.Net/wiki/Admin-API-Reference#admin-api-reference
or
https://github.com/wiremock/WireMock.Net/blob/master/src/WireMock.Net.Minimal/Settings/WireMockServerSettings.cs#L59
@StefH commented on GitHub (Jun 4, 2025):
@DannyBoyIT
Note that the matching details is also visible in the logging (I thjnk).
@DannyBoyIT commented on GitHub (Jun 10, 2025):
I got it to work by using a
.ToString()withCultureInfo.CurrentCultureon the expectedDateTime.It seems that the matching criterion for dates is much stricter than the matching dotnet does for the endpoint parameters when passing a
DateTimeparameter both as a body and as a query parameter. The dotnet endpoint seem to understand the given date without any culture conversion needed.