2

I'm using Microsoft's Visual Studio Test Tools and Moq for unit testing. I have a method that raises an event and I need to verify that the event's message is correct.

For example, the method calls this line of code:

_myEventPublisher.RaiseEvent(new MyEvent(message: myMessage))

And I need to verify the content of myMessage is correct.

I can successfully verify that the event is raised, with this line of code in the unit test:

For<IMyEventPublisher>()
                .Verify(x => x.RaiseEvent(It.IsAny<IMyEvent>()), Times.Exactly(1));

But I can't figure out how to verify the IMyEvent.Message string.

Robert Corvus
  • 2,054
  • 23
  • 30

1 Answers1

3
It.Is<IMyEvent>(m => Message == expected)

instead of

It.IsAny<IMyEvent>()
Sergei Rogovtcev
  • 5,804
  • 2
  • 22
  • 35