简体   繁体   English

我如何单元测试NServiceBus.Configure.WithWeb()?

[英]How do I Unit Test NServiceBus.Configure.WithWeb()?

I'm building a WCF service that receives requests on an external IP and translates them into messages that are sent via NServiceBus. 我正在构建一个WCF服务,它接收外部IP上的请求并将它们转换为通过NServiceBus发送的消息。

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. 我的一个单元测试调用Global.Application_Start() ,它执行应用程序的配置,然后尝试解析Web服务以验证容器是否可以构建所有依赖项。

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?). 这在我的Windows服务中使用Configure.With()时工作正常,但是在这种情况下对Configure.WithWeb()的调用失败(可能是因为“bin”目录不存在?)。

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? 是否可以对调用Configure.WithWeb()的方法进行单元测试,还是应该使用带有目录名的Configure.With()的重载?

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

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容器将使用这个而不是通常的基于Web的容器:

IoC.Register<IRunAtStartup, NonWebRunAtStartup>(); 

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). 这让我遇到了一个不同的错误,我还在讨论这个问题,我会问一个单独的问题(现在NSB无法加载NServiceBus.Core.dll中的程序集,例如Antlr3.Runtime.dll) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM