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.TestingInstall-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); } }
unit-testing nancy
scott pascoe
source share