12

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

Filip De Vos
  • 11,568
  • 1
  • 48
  • 60
biofractal
  • 18,963
  • 12
  • 70
  • 116

1 Answers1

19

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");
});
TheCodeJunkie
  • 9,378
  • 7
  • 43
  • 54