我如何单元测试NServiceBus.Configure.WithWeb()? [英] How do I Unit Test NServiceBus.Configure.WithWeb()?

查看:142
本文介绍了我如何单元测试NServiceBus.Configure.WithWeb()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个外部IP接收请求,并将它们转换成通过NServiceBus发送的消息的WCF服务。

I'm building a WCF service that receives requests on an external IP and translates them into messages that are sent via NServiceBus.

我的一个单元测试调用的 Global.Application_Start(),它执行应用程序的配置,然后再尝试解析Web服务
验证该容器可以建立所有的相关性

One of my unit tests invokes Global.Application_Start(), which performs the configuration of the application, and then attempts to resolve the web service to validate that the container can build up all of the dependencies.

这工作得很好,当我使用 Configure.With()在我的窗口服务,但
调用 Configure.WithWeb()失败,在这种情况下(这大概是因为bin的
目录不存在吗?)。

This works fine when I'm using Configure.With() in my windows services, but the call to Configure.WithWeb() fails in this context (presumably because the "bin" directory does not exist?).

是否有可能进行单元测试调用 Configure.WithWeb(),方法或我应该
只使用 Configure.With过载(),需要一个目录名?

Is it possible to unit test a method that calls Configure.WithWeb(), or should I just use the overload for Configure.With() that takes a directory name?

推荐答案

我创建了一个新的启动类,像这样:

I created a new startup class like so:

public class NonWebRunAtStartup : IRunAtStartup
{
    public void InitializeInfrastructure(object container)
    {
        Configure.With()
            .StructureMapBuilder((IContainer) container)
            .Log4Net()
            .XmlSerializer()
            .MsmqTransport()
            .UnicastBus()
            .LoadMessageHandlers()
            .CreateBus()
            .Start();
    }
}

在我的测试之后,我保证我的IOC容器将使用这一个,而不是通常的基于Web酮通过添加这对我的测试

Then in my test, I ensured that my IOC container would use this one instead of the usual web-based one by adding this to my test:

IoC.Register<IRunAtStartup, NonWebRunAtStartup>(); 

这让我到一个不同的错误,我还在与战斗,我会问作为一个单独的问题(现在NSB无法加载在NServiceBus.Core.dll,如Antlr3.Runtime.dll组件)。

This got me to a different error, which I'm still fighting with, which I'll ask as a separate question (now NSB can't load assemblies that are in NServiceBus.Core.dll, such as Antlr3.Runtime.dll).

这篇关于我如何单元测试NServiceBus.Configure.WithWeb()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆