南希测试没有发现其他装配航线 [英] Nancy test doesn't find route in other assembly

查看:167
本文介绍了南希测试没有发现其他装配航线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下规格(使用Machine.Specifications或mSpec):

I have the following spec (using Machine.Specifications or mSpec):

public class when_a_user_logs_in_successfully
{
    static Browser _browser;
    static BrowserResponse _response;

    Establish context = () =>
        {
            var bootstrapper = new ConfigurableBootstrapper();

            _browser = new Browser(bootstrapper);
        };

    Because of = () => _response = _browser.Get("/Login", with => with.HttpRequest());    

    It should_return_a_successful_response = () => _response.Body.ShouldNotBeNull();
}



从规范的路径应该找到以下模块:

The route from the spec should find the following module:

public class LoginModule : NancyModule
{
    public LoginModule()
    {
        Get["/Login"] = parameters => "test";
    }
}



但由于某些原因,该响应具有的状态NOTFOUND,并抛出一个异常说流被关闭/设置在机身。我的规格的解决方案必须包含的LoginModule集的引用。还有什么应该怎么做,使规范查找模块中的路线?

But for some reason, the response has a status of "NotFound" and a Body that throws an exception saying the stream is closed/disposed. My specs solution has a reference to the assembly that contains the LoginModule. What else should I do to make the spec find the route in the module?

推荐答案

那是因为你没有任何硬引用其他组件(即你不是在那里直接使用任何类型的),因为的.NET不会加载它,南希将找不到它。

It's because you don't have any "hard reference" to the other assembly (i.e. you're not using any of the types in there directly), because of that .Net doesn't load it and Nancy won't find it.

我们有,你可以用它来加载程序集的AppDomainAssemblyTypeScanner(那里面有几个方法可以用来加载一个通配符组DLL),或者你可以bodge它通过增加在主要部件的类型之一的变量到你的测试组件。

We have an AppDomainAssemblyTypeScanner that you can use to load your assemblies (there's a few methods in there you can use to load a wildcard set of DLLs), or you can bodge it by adding a variable of one of the types in your main assembly into your test assembly.

我觉得在未来,我们将不得不改变测试运行加载每个DLL可以在默认情况下发现,随着改变,如果它会导致问题的选项。

I think in the future we'll have to change the test runner to load every DLL it can find by default, with the option to change that if it causes issues.

这篇关于南希测试没有发现其他装配航线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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