Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't `DefaultNancyBoostrapper` find my NancyModule

I'm just getting my feet wet in Nancy. I was really excited to see the Testing process in the Wiki, but when I tried the following I couldn't get it work pass the tests at first.

Using VS2010

  1. Created Empty ASP.NET Web Application Project: Notify.App
  2. Install-Package Nancy.Hosting.AspNet
  3. Created simple Module as listed below: NotifyModule
  4. Created Class Library Project: Notify.UnitTests
  5. Install-Package Nancy.Testing
  6. Install-Package XUnit
  7. Created simple first test: BaseUrlSpec.cs

Using DefaultNancyBootstrapper the test fails with HttpStatusCode.NotFound.

If I replace the bootstrapper definition with:

var bootstrapper = new ConfigurableBootstrapper(
                          with => 
                             with.Module<NotifyModule>());

then the test passes. I don't understand why the SDHP using the DefaultNancyBootstrapper didn't work? Did I do something wrong to make it break, or am I missing details in my understanding?


NotifyModule

using Nancy;
public class NotifyModule : NancyModule {
    public NotifyModule() {
        Get["/"] = _ => HttpStatusCode.OK;
    }
}

BaseUrlSpec

using Nancy;
using Nancy.Testing;
using Notify.App;
using Xunit;
public class BaseUrlSpec
{
    [Fact]
    public void ShouldRespondOk()
    {
        var bootstrapper = new DefaultNancyBoostrapper();
        var app = new Browser(bootstrapper);
        var response = app.Get("/", with => with.HttpRequest());
        var statusCode = response.StatusCode;
        Assert.Equal(HttpStatusCode.OK, statusCode);
    }
}
like image 240
scott-pascoe Avatar asked Mar 04 '13 17:03

scott-pascoe


1 Answers

You need to make sure the assembly containing your route is loaded. Referencing a type from your assembly ensures this, therefore the version using the configurable bootstrapper works. To make the other one work, just add a reference to some type from your assembly. No need to instantiate it.

like image 88
Christian Horsdal Avatar answered Nov 09 '22 17:11

Christian Horsdal