Query string match on DateTimeOffset is not working #211

Closed
opened 2025-12-29 14:25:14 +01:00 by adam · 9 comments
Owner

Originally created by @viktorpeacock on GitHub (Sep 19, 2019).

Hi,

I am sending two values via a query string and I am trying to configure wiremock to respond when these two values come through. First is an int and it works fine. Second is a DateTimeOffset in the following format:

"yyyy-MM-ddTHH\\:mm\\:ss.fffzzz"

I have tried using the ExactValue matcher as so:

public static void AddQueryStringValueMatch(this RequestModel requestModel, KeyValuePair<string, string> queryStringItem)
        {
            var queryStringMatch = new ParamModel
            {
                IgnoreCase = true,
                Name = queryStringItem.Key,
                Matchers = new[]
                {
                    new MatcherModel
                    {
                        Name = "ExactMatcher",
                        Pattern = queryStringItem.Value,
                        IgnoreCase = true,
                        RejectOnMatch = false
                    }
                }
            };

            if (requestModel.Params == null)
                requestModel.Params = new List<ParamModel>();

            requestModel.Params.Add(queryStringMatch);
        }

This does not work and the following is returned from the wiremock:

[Error] : HttpStatusCode set to 400 System.ArgumentException: values
at WireMock.Validation.Check.HasNoNulls[T](IList1 value, String parameterName) at WireMock.Matchers.ExactMatcher..ctor(MatchBehaviour matchBehaviour, String[] values) at WireMock.Serialization.MatcherMapper.Map(MatcherModel matcher) at System.Linq.Enumerable.SelectArrayIterator2.MoveNext()
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at WireMock.Server.FluentMockServer.InitRequestBuilder(RequestModel requestModel, Boolean pathOrUrlRequired)
at WireMock.Server.FluentMockServer.DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Nullable`1 guid, String path)
at WireMock.Server.FluentMockServer.MappingsPost(RequestMessage requestMessage)

However, when I use a standard dateTimeOffset.ToString(), then it works fine and the following is configured:

 {
          "Name": "dateTime",
          "IgnoreCase": true,
          "Matchers": [
            {
              "Name": "ExactMatcher",
              "Pattern": "6/20/2021 5:16:56 AM +01:00"
            }
          ]
        }

Is there any guidance/examples on how to work with datetime/datetimeoffset in a specific format? I thought it would treat it just like any other string.

Originally created by @viktorpeacock on GitHub (Sep 19, 2019). Hi, I am sending two values via a query string and I am trying to configure wiremock to respond when these two values come through. First is an int and it works fine. Second is a DateTimeOffset in the following format: `"yyyy-MM-ddTHH\\:mm\\:ss.fffzzz"` I have tried using the ExactValue matcher as so: ``` c# public static void AddQueryStringValueMatch(this RequestModel requestModel, KeyValuePair<string, string> queryStringItem) { var queryStringMatch = new ParamModel { IgnoreCase = true, Name = queryStringItem.Key, Matchers = new[] { new MatcherModel { Name = "ExactMatcher", Pattern = queryStringItem.Value, IgnoreCase = true, RejectOnMatch = false } } }; if (requestModel.Params == null) requestModel.Params = new List<ParamModel>(); requestModel.Params.Add(queryStringMatch); } ``` This does not work and the following is returned from the wiremock: [Error] : HttpStatusCode set to 400 System.ArgumentException: values at WireMock.Validation.Check.HasNoNulls[T](IList`1 value, String parameterName) at WireMock.Matchers.ExactMatcher..ctor(MatchBehaviour matchBehaviour, String[] values) at WireMock.Serialization.MatcherMapper.Map(MatcherModel matcher) at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext() at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at WireMock.Server.FluentMockServer.InitRequestBuilder(RequestModel requestModel, Boolean pathOrUrlRequired) at WireMock.Server.FluentMockServer.DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Nullable`1 guid, String path) at WireMock.Server.FluentMockServer.MappingsPost(RequestMessage requestMessage) However, when I use a standard dateTimeOffset.ToString(), then it works fine and the following is configured: ``` js { "Name": "dateTime", "IgnoreCase": true, "Matchers": [ { "Name": "ExactMatcher", "Pattern": "6/20/2021 5:16:56 AM +01:00" } ] } ``` Is there any guidance/examples on how to work with datetime/datetimeoffset in a specific format? I thought it would treat it just like any other string.
adam added the bug label 2025-12-29 14:25:14 +01:00
adam closed this issue 2025-12-29 14:25:14 +01:00
Author
Owner

@StefH commented on GitHub (Sep 19, 2019):

The issue is that when you post a mapping like this:

"Params": [
            {
                "Name": "dateTime",
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "2019-09-19T18:02:31.7039950+02:00"
                    }
                ]
            }
        ]

The string value 2019-09-19T18:02:31.7039950+02:00 is actually converted to real DateTime, this means that some code fails.

I'll investigate if this can be solved.

@StefH commented on GitHub (Sep 19, 2019): The issue is that when you post a mapping like this: ``` js "Params": [ { "Name": "dateTime", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "2019-09-19T18:02:31.7039950+02:00" } ] } ] ``` The string value `2019-09-19T18:02:31.7039950+02:00` is actually converted to real DateTime, this means that some code fails. I'll investigate if this can be solved.
Author
Owner

@viktorpeacock commented on GitHub (Sep 19, 2019):

Thank you. I was looking through code myself but it's difficult to get up to speed with it as I don't know how it all fits together. Maybe in future you could give a high level overview of the solution so that others can get up and running and contribute :-) thank you!

@viktorpeacock commented on GitHub (Sep 19, 2019): Thank you. I was looking through code myself but it's difficult to get up to speed with it as I don't know how it all fits together. Maybe in future you could give a high level overview of the solution so that others can get up and running and contribute :-) thank you!
Author
Owner

@StefH commented on GitHub (Sep 19, 2019):

I've made a fix.

Can you please try MyGet version : WireMock.Net.1.0.32-ci-11907

Can be tested with request like:
http://xxx/param2?dateTime=2019-09-19T18:02:31.7039950%2B02:00

@StefH commented on GitHub (Sep 19, 2019): I've made a fix. Can you please try MyGet version : WireMock.Net.1.0.32-ci-11907 Can be tested with request like: `http://xxx/param2?dateTime=2019-09-19T18:02:31.7039950%2B02:00`
Author
Owner

@viktorpeacock commented on GitHub (Sep 20, 2019):

Thank you for such a fast turnaround! Can you please update a Docker image as we use this in K8s to simulate our dependencies?

@viktorpeacock commented on GitHub (Sep 20, 2019): Thank you for such a fast turnaround! Can you please update a Docker image as we use this in K8s to simulate our dependencies?
Author
Owner

@StefH commented on GitHub (Sep 20, 2019):

I'll create a new official version tonight and also a new docker.

@StefH commented on GitHub (Sep 20, 2019): I'll create a new official version tonight and also a new docker.
Author
Owner

@StefH commented on GitHub (Sep 20, 2019):

@viktorpeacock : do double check : did you test it ?

@StefH commented on GitHub (Sep 20, 2019): @viktorpeacock : do double check : did you test it ?
Author
Owner

@viktorpeacock commented on GitHub (Sep 20, 2019):

Hi Stef,

Yes. The following configuration and request worked for me:

[
  {
    "Guid": "1f4764d6-db9e-44c6-a78b-794cb13dee72",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/test",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ],
      "Params": [
        {
          "Name": "dateTime",
          "IgnoreCase": true,
          "Matchers": [
            {
              "Name": "ExactMatcher",
              "Pattern": "2019-09-20T11:03:17.221+00:00"
            }
          ]
        }
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyDestination": "SameAsSource",
      "Body": "{ \"result\": \"2019-09-20T11:03:17.221+00:00}",
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }
]

Request: http://localhost:9092/test?dateTime=2019-09-20T11%3A03%3A17.221%2B00%3A00

Response: { "result": "2019-09-20T11:03:17.221+00:00}

@viktorpeacock commented on GitHub (Sep 20, 2019): Hi Stef, Yes. The following configuration and request worked for me: ``` [ { "Guid": "1f4764d6-db9e-44c6-a78b-794cb13dee72", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test", "IgnoreCase": false } ] }, "Methods": [ "GET" ], "Params": [ { "Name": "dateTime", "IgnoreCase": true, "Matchers": [ { "Name": "ExactMatcher", "Pattern": "2019-09-20T11:03:17.221+00:00" } ] } ] }, "Response": { "StatusCode": 200, "BodyDestination": "SameAsSource", "Body": "{ \"result\": \"2019-09-20T11:03:17.221+00:00}", "Headers": { "Content-Type": "application/json" } } } ] ``` Request: http://localhost:9092/test?dateTime=2019-09-20T11%3A03%3A17.221%2B00%3A00 Response: `{ "result": "2019-09-20T11:03:17.221+00:00}`
Author
Owner

@StefH commented on GitHub (Sep 20, 2019):

I'll create a new official version tonight and also a new docker.

@StefH commented on GitHub (Sep 20, 2019): I'll create a new official version tonight and also a new docker.
Author
Owner

@viktorpeacock commented on GitHub (Sep 20, 2019):

You are a star! Thank you very much :-)

@viktorpeacock commented on GitHub (Sep 20, 2019): You are a star! Thank you very much :-)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#211