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

Ambiguity when mocking RequestURI with QueryString #42

Open
jesperj-apmm opened this issue Dec 27, 2022 · 1 comment
Open

Ambiguity when mocking RequestURI with QueryString #42

jesperj-apmm opened this issue Dec 27, 2022 · 1 comment

Comments

@jesperj-apmm
Copy link

Hey,

Thank you for writing this awesome library !

While using it I ran into a fun challenge :)

While mocking a Http Request with RequestURI and QueryString, like this:

_mockHttp = new MockHttpHandler();
        _mockHttp.When( matching => matching
                .Method("GET")
                .RequestUri("https://magic.rest.api.com/awesomepath")
                .QueryString("q=name:<name>&sort=desc")
            .Respond( with => with
                .StatusCode(200)
                .Body(<json string>)
                .ContentType("application/json"))
            .Verifiable();

The request matcher does not match the request even though the InvokedRequest and the Matcher URI and QueryString, combined is a perfect match.

To make the request work, I need to add '*' at the end of the URI, like this:

....
                .Method("GET")
                .RequestUri("https://magic.rest.api.com/awesomepath*")
                .QueryString("q=name:<name>&sort=desc")
....

When I looked through the code, here:

public static RequestMatching RequestUri(this RequestMatching builder, string requestUri)
, I see that the builder does not pass the allowWildCard bool and it's defaulted to true, but I'll write a few test to verify that assumption.

I'll be happy to give it a try and create a PR with a fix if this is not intended behaviour.

@skwasjer
Copy link
Owner

skwasjer commented Dec 31, 2022

Thanks for inquiring.

This is by design (historically that is, before .QueryString() existed). Feel free to offer a PR but we have to be careful with the change in behavior as this may break existing (test) projects.

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