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

半世苍凉 提交于 2019-12-07 09:00:44

问题


I'm building a WCF service that receives requests on an external IP and translates them into messages that are sent via 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.

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?).

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?


回答1:


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.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).



来源:https://stackoverflow.com/questions/3752734/how-do-i-unit-test-nservicebus-configure-withweb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!