Nancy 测试在其他程序集中找不到路线

发布于 2024-12-15 16:17:17 字数 836 浏览 0 评论 0原文

我有以下规范(使用 Machine.Specifications 或 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();
}

规范中的路由应该找到以下模块:

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

但由于某种原因,响应的状态为“NotFound”,并且 Body 抛出异常,表示流是关闭/处置。我的规格解决方案引用了包含 LoginModule 的程序集。我还应该做什么才能使规范找到模块中的路由?

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";
    }
}

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-12-22 16:17:17

这是因为您没有对其他程序集的任何“硬引用”(即您没有直接使用其中的任何类型),因为 .Net 不会加载它,Nancy 也找不到它。

我们有一个 AppDomainAssemblyTypeScanner,您可以使用它来加载程序集(其中有一些方法可以用来加载一组通配符 DLL),或者您可以通过将主程序集中的一种类型的变量添加到您的测试组件。

我认为将来我们必须更改测试运行程序以加载默认情况下可以找到的每个 DLL,并且可以选择在导致问题时进行更改。

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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文