Consider the below method that updates a person and publishes an event through the PRISM EventAggregator to indicate that the person has been updated.
I would like to unit test that the message is sent with the correct payload. In this case that would mean the correct personId.
public void UpdatePerson(int personId)
{
// Do whatever it takes to update the person
// ...
// Publish a message indicating that the person has been updated
_eventAggregator
.GetEvent<PersonUpdatedEvent>()
.Publish(new PersonUpdatedEventArgs
{
Info = new PersonInfo
{
Id = personId,
UpdatedAt = DateTime.Now
};
});
}
I know that I can create a substitute for the event aggregator:
var _eventAggregator = Substitute.For<IEventAggregator>();
However, I don't know how to detect when a message is sent and how to check its payload.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…