Nancy test doesn't find route in other assembly

北城余情 提交于 2019-12-02 11:04:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8139096/nancy-test-doesnt-find-route-in-other-assembly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!