sco*_*coe 8 unit-testing nancy
我只是在南希弄湿了脚.我很高兴看到Wiki中的测试过程,但是当我尝试以下操作时,我无法通过测试来完成测试.
使用VS2010
Empty ASP.NET Web Application Project:Notify.AppInstall-Package Nancy.Hosting.AspNetClass Library项目:Notify.UnitTestsInstall-Package Nancy.TestingInstall-Package XUnit使用DefaultNancyBootstrapper测试失败了HttpStatusCode.NotFound.
如果我用以下内容替换bootstrapper定义:
var bootstrapper = new ConfigurableBootstrapper(
with =>
with.Module<NotifyModule>());
Run Code Online (Sandbox Code Playgroud)
然后测试通过. 我不明白为什么使用DefaultNancyBootstrapper的SDHP不起作用?我做错了什么让它破裂,还是我在理解中遗漏了细节?
NotifyModule
using Nancy;
public class NotifyModule : NancyModule {
public NotifyModule() {
Get["/"] = _ => HttpStatusCode.OK;
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
您需要确保加载包含您的路由的程序集.引用程序集中的类型可确保这一点,因此使用可配置引导程序的版本可以正常工作.要使另一个工作,只需在程序集中添加对某些类型的引用.无需实例化它.