Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching WithParam on OData End Points #72

Closed
christamlyn-bridge opened this issue Dec 12, 2017 · 6 comments
Closed

Matching WithParam on OData End Points #72

christamlyn-bridge opened this issue Dec 12, 2017 · 6 comments
Assignees

Comments

@christamlyn-bridge
Copy link

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

http:https://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

@StefH StefH self-assigned this Dec 12, 2017
StefH added a commit that referenced this issue Dec 12, 2017
Fix for url encoded path + params (1.0.2.10)
@StefH
Copy link
Collaborator

StefH commented Dec 12, 2017

Problem was related to url-encoding.

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

@christamlyn-bridge
Copy link
Author

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

@StefH
Copy link
Collaborator

StefH commented 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(); ?

@christamlyn-bridge
Copy link
Author

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

@StefH
Copy link
Collaborator

StefH commented Dec 13, 2017

Yes indeed. Escaping in your strings is not needed.

If all is fine, you can close this issue ?

@StefH
Copy link
Collaborator

StefH commented Dec 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants