当我尝试测试Nancy模块时,我得到以下内容:
StructureMap异常代码:205缺少请求的实例属性 InstanceKey的“modulePath”“Nancy.Testing.Fakes.FakeNancyModule”
这是我的测试:
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();
}
这是我的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>());
}
}
答案 0 :(得分:2)
我遇到了同样的问题,发现this post让我得到了对我有用的答案
在您的引导程序中,添加以下内容:
container.Configure(x => {
x.SelectConstructor(()=>new FakeNancyModule());
x.AddRegistry<BlurtsRegistry>();
})
至少这应该有效,直到StructureMapBootstrapper
本身更新。
答案 1 :(得分:0)
在0.10中,您必须通过覆盖ConfigureRequestContainer(IContainer container, NancyContext context)
看起来像这样:
protected override void ConfigureRequestContainer(IContainer container, NancyContext context)
{
container.Configure(x =>
{
x.SelectConstructor(() => new FakeNancyModule());
});
base.ConfigureRequestContainer(container, context);
}
他们说他们会尝试将其修复为0.11
https://github.com/NancyFx/Nancy.Bootstrappers.StructureMap/issues/8