Why "DefaultNancyBoostrapper" does not find my NancyModule

I just wet my feet in Nancy. I was very happy to see the testing process in the Wiki, but when I tried the following, I could not get it to work, pass the tests first.

Using VS2010

  • Created by Empty ASP.NET Web Application Project : Notify.App
  • Install-Package Nancy.Hosting.AspNet
  • A simple module was created as follows: NotifyModule
  • Created Class Library Project: Notify.UnitTests
  • Install-Package Nancy.Testing
  • Install-Package XUnit
  • Created a simple first test: BaseUrlSpec.cs

Using DefaultNancyBootstrapper , the test failed with the HttpStatusCode.NotFound error.

If I replaced the bootstrapper definition with:

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

then the test passes. I do not understand why SDHP using DefaultNancyBootstrapper did not work? Am I doing something wrong to make it break, or am I missing the 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); } } 
+8
unit-testing nancy
source share
1 answer

You need to make sure that the assembly containing your route is loaded. This allows you to refer to the type of your assembly, so the version with a custom loader works. To do another job, just add a link to some type from your assembly. No need to create it.

+6
source share

All Articles