南希测试项目找不到意见 [英] Nancy testing project can't find views

查看:151
本文介绍了南希测试项目找不到意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试测试从测试项目南希模块时撞了一下一个绊脚石。我测试的代码看起来非常标准:

Hit a bit of a stumbling block when trying to test a Nancy module from a test project. My test code looks pretty standard:

[TestMethod]
public void Should_return_status_ok_when_route_exists()
{
    // Given
    var bootstrapper = new DefaultNancyBootstrapper();
    var browser = new Browser(bootstrapper);

    // When
    var result = browser.Get("/", with =>
    {
        with.HttpRequest();
    });

    // Then
    Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
}



我得到一个无法当我的模块试图渲染视图定位视图例外。如果我运行该项目正常的模块发现的看法。从测试项目,该模块不能找到它被调用时,它的唯一的。

I get an unable to locate view exception when my module tries to render the view. If I run the project normally the module finds the view. It's only when invoked from the test project that the module can't find it.

推荐答案

的问题是,意见AREN ŧ望其项背的测试项目,并自IRootPathProvider是在错误的地方指指点点,它无法找到他们。两种方法来解决这个问题是使用ConfigurableBootstrapper(这或多或少是一样的默认之一,但覆盖的东西初始化时的可能性),并告诉它使用自定义的根路径提供

The problem is that the views aren't anywhere close your test project, and since the IRootPathProvider is pointing at the wrong place, it can't find them. Two ways to get around this is use the ConfigurableBootstrapper (which is more or less the same as the Default one, but the the possibility to override stuff when initialized) and tell it to use your custom root path provider

var bootstrapper = new ConfigurableBootstrapper(with => {
    with.RootPathProvider<CustomRootPathProvider>();
});



这样,你会落实公共类CustomRootPathProvider:IRootPathProvider 并指出它在正确的地方。

You would then implement public class CustomRootPathProvider : IRootPathProvider and point it in the right place.

第二个解决办法是设置你的观点总是复制到输出目录,我认为还应该解决它

The second solution would be to set your views to always copy to the output directory, I believe that should also solve it

这篇关于南希测试项目找不到意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆