4

I'm attempting to test the following publishing-code (classes and properties are adjusted for example-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;
                                    });
}

The test-code (altered 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 just fine if the failedMessages array only contains one message, but fails with the following error 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 messages in one Publish?

Charles
  • 50,943
  • 13
  • 104
  • 142
Yngve B-Nilsen
  • 9,606
  • 2
  • 36
  • 50

1 Answers1

0

This is a bug - https://github.com/NServiceBus/NServiceBus/issues/489

Andreas Öhlund
  • 5,263
  • 20
  • 24
  • Uncertain as to how I missed this. I did search the issuelog for NServiceBus, but it's pretty much what I concluded with after checking the sourcecode for the NServiceBus.Testing project... – Yngve B-Nilsen Jun 20 '12 at 21:35
  • The bug was added recently so that might be why you missed it:) – Andreas Öhlund Jun 21 '12 at 06:01