Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6558163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:09:57+00:00 2026-05-25T13:09:57+00:00

Ok – I love NancyFx. Writing a web application with that few lines is

  • 0

Ok – I love NancyFx. Writing a web application with that few lines is just amazing!

But how do you test drive your NancyModules on the unit level?

Please note that I am aware of the excellent testframework supplied with Nancy (Nancy.Testing on NuGet), which gives excellent ways to test the whole (almost) application stack. But now I mean the unit level test I use to flesh out the contents of my NancyModule, in TDD fashion.

Since the routes are defined in the constructor, often together with a lamda expression that constitute the whole action, it feels a bit “unreachable” from a unit test. But have I missed something obvious on how to test the actions of the route?

For example, how would a unit test for this simple application look?

public class ResouceModule : NancyModule 
{
   private IProductRepository _productRepo;

   public ResourceModule(IProductRepository repo) : base("/products") 
   {
        Get["/list"] = parameters => { 
           return View["productList.cshtml", repo.GetAllProducts()];
        };
   }
}

See there – now I wrote the production code before the test… 🙂 Any suggestions on how to start with the test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:09:58+00:00Added an answer on May 25, 2026 at 1:09 pm

    You can do test first dev with the testing tools we provide:

    • In your test startup configure a bootstrapper that only contains the module you have under test and any any fake objects you want.
    • In your test execute a specific route (like GET /list) – you might want a small helper for this to remove some repeated code perhaps.
    • Assert on what comes back – you have full access to the request and response objects (for headers, cookies etc), along with helpers for HTML bodies and, coming in 1.8, helpers for handing JSON, XML and just string responses in the body.
    • Move onto the next route, rinse and repeat.

    Ok, so you’re not just testing the module, but if you look at the call stack, there’s not much going on before or after you hit your route so it’s not that big of a deal in my book 🙂 If you really do want to test the module in complete isolation then you can just construct it yourself and poke the individual routes accordingly (they’re just dictionaries in the module).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP application that stores PHP datetime to my MySQL table. I
Have a webpage that will be viewed by mainly IE users, so CSS3 is
I have a simple restful service that transforms a JAXB-anntotated beans to response XML
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I am getting the value from web service like &gt;&lt;&amp;&nbsp; etc. I want to
I need to clean up various Word 'smart' characters in user input, including but
I am generating some text to be shown on a web-site, and use HttpUtility.HtmlEncode
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I am getting notice on line 30 that twetout is undefined variable <?php $username

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.