测试事件是否从处理程序发布

时间:2015-12-31 06:33:13

标签: nunit nservicebus

我是否可以获得如何测试事件是否从给定处理程序发布的示例。

           var cmd = new Catalogue()
            {
                CatalogueCode = "",
                CatalogueType = "",
                CustomerSegmentCode = "",
                DisplayName = "",
                EffectiveDate = null,
                Products = null
            };
            Test.Handler(bus => new CatalogueAddedCommandHandler(bus))
                .ExpectPublish<ICatalogue>(e => e.CatalogueCode == cmd.CatalogueCode).OnMessage(cmd);

当我调试测试用例时,它显示在Test.Handler中找不到异常接口。

1 个答案:

答案 0 :(得分:0)

我认为您需要致电 using NServiceBus; using NServiceBus.Testing; using NUnit.Framework; [TestFixture] public class Tests { [Test] public void Run() { Test.Initialize(c => c.Conventions().DefiningEventsAs(t => t == typeof (ICatalogue))); var cmd = new Catalogue() { CatalogueCode = "TEST" }; Test.Handler<CatalogueAddedCommandHandler>() .ExpectPublish<ICatalogue>(e => e.CatalogueCode == cmd.CatalogueCode) .OnMessage(cmd); } } public interface ICatalogue { string CatalogueCode { get; set; } } public class Catalogue { public string CatalogueCode { get; set; } } public class CatalogueEvent : ICatalogue { public string CatalogueCode { get; set; } } public class CatalogueAddedCommandHandler : IHandleMessages<Catalogue> { public IBus Bus { get; set; } public void Handle(Catalogue message) { Bus.Publish<ICatalogue>(e => e.CatalogueCode = message.CatalogueCode); } }

您可以在the Particular docs website

上找到相关文档

更新:

{{1}}

这有帮助吗?