1

当我尝试测试 Nancy 模块时,我得到以下信息:

StructureMap 异常代码:205 InstanceKey“Nancy.Testing.Fakes.FakeNancyModule”缺少请求的实例属性“modulePath”

这是我的测试:

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>());
    }        
}
4

2 回答 2

2

我遇到了同样的问题,发现这篇文章让我找到了对我有用的答案

在您的引导程序中,添加以下内容:

container.Configure(x => {
    x.SelectConstructor(()=>new FakeNancyModule());
    x.AddRegistry<BlurtsRegistry>();
})

至少在StructureMapBootstrapper更新自身之前这应该有效。

于 2011-12-15T20:14:30.897 回答
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

于 2012-03-12T18:18:14.507 回答