Reputation: 13012
I get the following when I try to test a Nancy module:
StructureMap Exception Code: 205 Missing requested Instance property "modulePath" for InstanceKey "Nancy.Testing.Fakes.FakeNancyModule"
Here's my test:
public class when_a_user_logs_in_successfully
{
static Browser _browser;
static BrowserResponse _response;
Establish context = () =>
{
var bootstrapper = new BlurtsBootsrapper();
_browser = new Browser(bootstrapper); //throws exception here
};
Because of = () => _response = _browser.Get("/Login", with => with.HttpRequest());
It should_return_a_successful_response = () => _response.Body.ShouldNotBeNull();
}
Here's my BlurtsBootstrapper:
public class BlurtsBootsrapper : StructureMapNancyBootstrapper
{
protected override void ApplicationStartup(StructureMap.IContainer container, Nancy.Bootstrapper.IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
container.Configure(x => x.AddRegistry<BlurtsRegistry>());
}
}
Upvotes: 1
Views: 643
Reputation: 582
In 0.10 you must do this by overriding ConfigureRequestContainer(IContainer container, NancyContext context)
It looks like this:
protected override void ConfigureRequestContainer(IContainer container, NancyContext context)
{
container.Configure(x =>
{
x.SelectConstructor(() => new FakeNancyModule());
});
base.ConfigureRequestContainer(container, context);
}
They said they will try and fix it for 0.11
https://github.com/NancyFx/Nancy.Bootstrappers.StructureMap/issues/8
Upvotes: 0
Reputation: 3441
I ran into the same issue and found this post that led me to the answer that worked for me
In your bootstrapper, add the following:
container.Configure(x => {
x.SelectConstructor(()=>new FakeNancyModule());
x.AddRegistry<BlurtsRegistry>();
})
At least this should work until the StructureMapBootstrapper
itself is updated.
Upvotes: 2