TheFastCat
TheFastCat

Reputation: 3474

NancyFx Unit Testing How to pass browser route parameter via Testing Browser?

I am trying to pass a route parameter (not Query Paramter!) via Nancy.Testing.Browser object. I understand (now) how to send and consume query strings to/from my NancyModule:

var customerResponse = browser.Get("/customer/id", with =>
{
    with.HttpRequest();
    with.Query("{id}", alansIdGuid.ToString());
});

...

Get["/customer/{id}"] = parameters =>
{
    string idFromQuery = Request.Query.id;
    Customer customerFromId = _customerRepo.GetCustomerById(idFromQuery);
    return Response.AsJson<Customer>(customerFromId);
};

However - What I want to do is hit my route and retrieve my route parameter like so:

Get["/customer/{id}"] = parameters =>
{
    string id = parameters.id;
    Customer customerFromId = _customerRepo.GetCustomerById(id);
    return Response.AsJson<Customer>(customerFromId);
};  

How do I do I pass my Id parameter as a route parameter using Nancy.Testing.Browser?

-Without using Headers, Cookies or Query strings?

This has been a 3 hour search for a seemingly simple task! The following questions dance around the issue but don't resolve it:

Send parameter to Nancy module from test

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

Why are no query parameters being passed to my NancyFX module?

Upvotes: 4

Views: 1622

Answers (1)

TheFastCat
TheFastCat

Reputation: 3474

I am an idiot... I guess the answer was seemingly obvious to everyone else!

var customerResponse = browser.Get("/customer/" + alansIdGuid.ToString(), with =>
{             
    with.HttpRequest();
});

Simply append your query string/value to the end of the Request URL for the Nancy.Testing.Browser object you are using.

Upvotes: 5

Related Questions