Skip to content

Ambiguity when mocking RequestURI with QueryString #42

@jesperj-apmm

Description

@jesperj-apmm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions