4

我正在尝试测试以下发布代码(为示例目的调整了类和属性):

public void PublishMessages(List<SomeDummyClass> shareRegistrationResult)
{    
    var failedMessages = shareRegistrationResult
                                .Where(c => !c.WasRegistered)
                                .Select(c => CreateNotRegisteredMessageInstance(c.String1, c.String2)).ToArray();
    _bus.Publish(failedMessages);
}

private IMyMessage CreateNotRegisteredMessageInstance(string string1, string string2)
{
    return _bus.CreateInstance<IMyMessage>(message =>
                                    {
                                        message.String1 = string1;
                                        message.String2 = string2;
                                    });
}

测试代码(更改为匹配虚拟消息)

NServiceBus.Testing.Test.Handler(bus => new Publisher()
     .ExpectPublish<IMyMessage>(message => message.String1 == "Hello" && message.String2 == "World")
     .ExpectPublish<IMyMessage>(message => message.String1 == "Foo" && message.String2 == "Bar");

如果数组只包含一条消息,这工作得很好failedMessages,但当数组包含多条消息时失败并出现以下错误:

Rhino.Mocks.Exceptions.ExpectationViolationException : IBus.Publish(callback method: <>c__DisplayClass1c`1.<ExpectPublish>b__1b); Expected #1, Actual #0.
IBus.Publish(callback method: <>c__DisplayClass1c`1.<ExpectPublish>b__1b); Expected #1, Actual #0.

在一个发布中测试多条消息时如何使用 ExpectPublish 测试(或其他)的任何想法?

4

1 回答 1

0

这是一个错误 - https://github.com/NServiceBus/NServiceBus/issues/489

于 2012-06-20T19:07:35.997 回答