Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NancyFX: Routes with query string parameters always returns a 404 NotFound

I have a simple Nancy module. I want to pass in query string (q-s) parameters to the handler. If I do not have any q-s params everything is fine. As soon as I add a param then I get a 404 status code returned.

NancyModule

public class SimpleModule : NancyModule
{
    public SimpleModule()
    {
        Get["/"] = parameters => HttpStatusCode.OK;
    }
}

Unit Test - Passes

[Fact]
public void SimpleModule__Should_return_statusOK_when_passing_query_params()
{
    const string uri = "/";
    var response = Fake.Browser().Get(uri, with => with.HttpRequest());
    response.StatusCode.ShouldBe(HttpStatusCode.OK);
}

Unit Test - Fails

[Fact]
public void SimpleModule__Should_return_statusOK_when_passing_query_params()
{
    const string uri = "/?id=1";
    var response = Fake.Browser().Get(uri, with => with.HttpRequest());
    response.StatusCode.ShouldBe(HttpStatusCode.OK);
}

Thanks

like image 396
biofractal Avatar asked May 23 '12 11:05

biofractal


1 Answers

You don't pass in the query on the url, instead use the .Query method on the browser context

var result = browser.Get("/", with => {
    with.Query("key", "value");
});
like image 121
TheCodeJunkie Avatar answered Nov 13 '22 07:11

TheCodeJunkie