我只是在南希弄湿了我的脚。在 Wiki 中看到测试过程我真的很兴奋,但是当我尝试以下操作时,我一开始无法通过测试。
使用VS2010
- 创建
Empty ASP.NET Web Application Project
:Notify.App Install-Package Nancy.Hosting.AspNet
- 创建了如下所列的简单模块:NotifyModule
- 创建
Class Library
项目:Notify.UnitTests Install-Package Nancy.Testing
Install-Package XUnit
- 创建简单的第一个测试:BaseUrlSpec.cs
使用DefaultNancyBootstrapper
测试失败,出现HttpStatusCode.NotFound
.
如果我将bootstrapper
定义替换为:
var bootstrapper = new ConfigurableBootstrapper(
with =>
with.Module<NotifyModule>());
然后测试通过。 我不明白为什么使用 DefaultNancyBootstrapper 的 SDHP 不起作用?我是否做错了什么让它崩溃,或者我在理解中遗漏了细节?
通知模块
using Nancy;
public class NotifyModule : NancyModule {
public NotifyModule() {
Get["/"] = _ => HttpStatusCode.OK;
}
}
基本网址规范
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);
}
}