question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query string match on DateTimeOffset is not working

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
StefHcommented, Sep 20, 2019

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

1reaction
StefHcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing DateTimeOffset as WebAPI query string
The problem is the + (plus) char in the offset part, we should encode that. If the offset is - (minus) no need...
Read more >
datetimeoffset (Transact-SQL) - SQL Server
Supported string literal formats for datetimeoffset​​ These two formats are not affected by the SET LANGUAGE and SET DATEFORMAT session locale ...
Read more >
Working with datetime as string
Let's say some external component inserts data into my database, with a field called “startDate”. They store this value as an ISO 8601...
Read more >
Date/Time and Interval Functions and Operators
Description: Returns the date (no time part) when the current query reached the server. It can be used both as a keyword: CURRENT_DATE...
Read more >
Queries on date properties don't work
I am trying to do a query on a date property but it doesn't work. Not always. Here is some sample code: Initial...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found