ExpectPublish fails when Publish (params T [] messages) contains more than one message

I am trying to test the following publishing code (classes and properties are configured, for example, for purposes):

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

Test code (modified to match dummy messages)

 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"); 

This works fine if the failedMessages array contains only one message, but with the error the following error appears when the array has more than one message:

 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. 

Any ideas on how to use the ExpectPublish test (or something else) when testing multiple posts in a single post?

+4
source share

All Articles