Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top