If I target a message from ViewModelA to ViewModelB, is there a way to catch this notification from my unit test that is testing ViewModelA where the Message is raised?
Messenger.Default.Send<string, ViewModelB>("Something Happened");
If I target a message from ViewModelA to ViewModelB, is there a way to catch this notification from my unit test that is testing ViewModelA where the Message is raised?
Messenger.Default.Send<string, ViewModelB>("Something Happened");
I see two options:
First, you could mark ViewModelB with a "marker" interface, and use that instead of your actual class name.
Messenger.Default.Send<string, IMessageTarget>("Something Happened");
This is not my favorite solution, but it should work.
Or, you could register for messages with a specific token in ViewModelB while sending the disambiguated message from ViewModelA:
In ViewModelA:
Messenger.Default.Send<string>("Something Happened", "MessageDisambiguator");
In ViewModelB:
Messenger.Default.Register<string>(
this,
"MessageDisambiguator",
(action) => DoWork(action)
);
Much cleaner, and will still allow you to mock out ViewModelB for testing purposes.
There could be more options, but these are the ones that pop to the top of my head at this late hour...