Matching WithParam on OData End Points #54

Closed
opened 2025-12-29 14:21:48 +01:00 by adam · 6 comments
Owner

Originally created by @christamlyn-bridge on GitHub (Dec 12, 2017).

Originally assigned to: @StefH on GitHub.

Our test is making an HTTP call to an OData end point:

http://localhost:5021/navision/OData/Company('My Company')/School()?$filter=(substringof(Code, 'WA')

To match to this I have mocked:

 navServer
                    .Given(Request
                    .Create()
                    .WithPath(new WildcardMatcher($"/navision/OData/Company('My Company')/School*", ignoreCase: true))
                    .WithParam("$filter")
                    .UsingGet())
                    .ResponedWithSchoolData();

In the tests this is matching on the client request, however if I try and specify the parameter value it fails to match:

 navServer
                    .Given(Request
                    .Create()
                    .WithPath(new WildcardMatcher($"/navision/OData/Company('My Company')/School*", ignoreCase: true))
                    .WithParam("$filter", "(substringof(Code, 'WA')")
                    .UsingGet())
                    .ResponedWithSchoolData();

Is there any reason why using the value in the WithParam method would cause a mismatch?

Thanks

Originally created by @christamlyn-bridge on GitHub (Dec 12, 2017). Originally assigned to: @StefH on GitHub. Our test is making an HTTP call to an OData end point: `http://localhost:5021/navision/OData/Company('My Company')/School()?$filter=(substringof(Code, 'WA')` To match to this I have mocked: ``` navServer .Given(Request .Create() .WithPath(new WildcardMatcher($"/navision/OData/Company('My Company')/School*", ignoreCase: true)) .WithParam("$filter") .UsingGet()) .ResponedWithSchoolData(); ``` In the tests this is matching on the client request, however if I try and specify the parameter value it fails to match: ``` navServer .Given(Request .Create() .WithPath(new WildcardMatcher($"/navision/OData/Company('My Company')/School*", ignoreCase: true)) .WithParam("$filter", "(substringof(Code, 'WA')") .UsingGet()) .ResponedWithSchoolData(); ``` Is there any reason why using the value in the WithParam method would cause a mismatch? Thanks
adam closed this issue 2025-12-29 14:21:48 +01:00
Author
Owner

@StefH commented on GitHub (Dec 12, 2017):

Problem was related to url-encoding.

See new NuGet : https://www.nuget.org/packages/WireMock.Net/1.0.2.10

@StefH commented on GitHub (Dec 12, 2017): Problem was related to url-encoding. See new NuGet : https://www.nuget.org/packages/WireMock.Net/1.0.2.10
Author
Owner

@christamlyn-bridge commented on GitHub (Dec 13, 2017):

interestingly after upgrading to 1.0.2.10, none of my requests are matching now

@christamlyn-bridge commented on GitHub (Dec 13, 2017): interestingly after upgrading to 1.0.2.10, none of my requests are matching now
Author
Owner

@StefH commented on GitHub (Dec 13, 2017):

Can you checkout the example code? (https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.ConsoleApplication/MainApp.cs#L43)

I tried this:

server
  .Given(Request
    .Create()
    .WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))
    .WithParam("$filter", "(substringof(Code, 'WA')")
    .UsingGet())
  .RespondWith(Response.Create()
    .WithBody(@"{ ""result"": ""odata""}"));

It could be related to server.AllowPartialMapping(); ?

@StefH commented on GitHub (Dec 13, 2017): Can you checkout the example code? (https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.ConsoleApplication/MainApp.cs#L43) I tried this: ``` server  .Given(Request .Create() .WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true)) .WithParam("$filter", "(substringof(Code, 'WA')") .UsingGet()) .RespondWith(Response.Create() .WithBody(@"{ ""result"": ""odata""}")); ``` It could be related to `server.AllowPartialMapping();` ?
Author
Owner

@christamlyn-bridge commented on GitHub (Dec 13, 2017):

ah I see the difference, on the previous version I found I had to escape the spaces manually in my WilcardMatcher:

.WithPath(new WildcardMatcher("/navision/OData/Company('My%20Company')/School*", true))

But with the new module, you can use:

.WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))

Definite improvement! Thanks

@christamlyn-bridge commented on GitHub (Dec 13, 2017): ah I see the difference, on the previous version I found I had to escape the spaces manually in my WilcardMatcher: `.WithPath(new WildcardMatcher("/navision/OData/Company('My%20Company')/School*", true))` But with the new module, you can use: `.WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))` Definite improvement! Thanks
Author
Owner

@StefH commented on GitHub (Dec 13, 2017):

Yes indeed. Escaping in your strings is not needed.

If all is fine, you can close this issue ?

@StefH commented on GitHub (Dec 13, 2017): Yes indeed. Escaping in your strings is not needed. If all is fine, you can close this issue ?
Author
Owner

@StefH commented on GitHub (Dec 13, 2017):

Thanks for testing. If you have more questions, just ask!

@StefH commented on GitHub (Dec 13, 2017): Thanks for testing. If you have more questions, just ask!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#54