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
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");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With