Send parameter to Nancy module from test

I am trying to test a module with a parameter (below is just the code where I am trying to understand the problem)

public class StuffModule : NancyModule
{
    public StuffModule() : base("/Stuff")
    {
        Get["/All/"] = parameters =>
                       {
                           string str = parameters.one;
                           return Response.AsJson(str);
                       };
    }
}

private Browser _browser;

[SetUp]
public void SetUp()
{
    var module = new StuffModule(null);

    var mock = new Mock<IRecipeExtractor>();
    var bootstrapper = new ConfigurableBootstrapper(
            with => with.Dependency(mock.Object)
        );

    _browser = new Browser(bootstrapper);
}

[Test]
public void Can_extract_recipe_as_json()
{
    var result = _browser.Get("/Stuff/All/", with =>
    {
        with.HttpRequest();
        with.Query("one", "yes_one");
    });

    Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}

When running over code, I get nothing in my parameter variable. Some clues?

0
source share
1 answer

To capture parameters, you need to declare them as part of your part, for example /profile/{username}, which will lead to accessibility parameters.username.

You pass the querystring value to your test, available on Request.Query.one, and you can make sure that it matters withRequest.Query.one.HasValue

https://github.com/NancyFx/Nancy/wiki/Defining-routes https://github.com/NancyFx/Nancy/wiki/Testing-your-application

0

All Articles