WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.36k stars 200 forks source link

How to match date param to a certain date range when using the Admin Api Client #960

Closed doddi321 closed 1 year ago

doddi321 commented 1 year ago

I'm using Testcontainers and using the the admin client to create the mappings like so:

        await iLApi.ResetMappingsAsync();
        var mappingBuilder = iLApi.GetMappingBuilder();
        mappingBuilder.Given(m => m
            .WithRequest(req => req
                .UsingGet()
                .WithPath("/api/claimants/modified")
            )
            .WithResponse(rsp => rsp
                .WithStatusCode(StatusCodes.Status200OK)
                .WithBodyAsJson(ILModifiedClaimants)
            )
        ); 

I need to match a date query parameter to a certain date range, f.x. /api/claimants/modified?since=....

I know the LinqMatcher exists which seems fit my needs perfectly but the only thing that the .WithParams method accepts is the MatcherModel which seems to only support Regex.

Is what I am asking possible and if so how?

StefH commented 1 year ago

Hello @doddi321.

Good question.

I'll take look.

StefH commented 1 year ago

@doddi321 It should work, example:

[
  {
    "Guid": "41372914-1838-4c67-916b-b9aacdd096ce",
    "UpdatedAt": "2023-01-14T15:16:17",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/foo",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ],
      "Params": [
        {
          "Name": "test",
          "Matchers": [
            {
              "Name": "LinqMatcher",
              "Pattern": "it.Length < 10"
            }
          ]
        }
      ]
    },
    "Response": {
      "BodyDestination": "SameAsSource",
      "Body": "{ msg: \"Hello world!\"}"
    }
  }
]
StefH commented 1 year ago

https://github.com/WireMock-Net/WireMock.Net/pull/961