When using the Messaging center, there's no way to mock it as a dependency unless we write a wrapper layer around it.
In order to follow the SOLID principles and keep Xamarin Forms testable and easy to use:
* Define in an interface the methods we are currently using statically.
* Change the MessagingCenter class to have non static methods, implementing the interface created above.
* Create a singleton instance of the MessagingCenter that anyone can acquire so it keeps the same static behaviour the class had earlier.
If you follow this steps, developers using Xamarin Forms could inject into their classes an IMessagingCenter that could be mocked with Moq or similar tools, and the only change required in their code is replace:
I like your suggestions.
Not sure if this is an option for you, but you could also try checking out the event aggregator in PRISM.
Refering to this? https://msdn.microsoft.com/en-us/library/ff921122.aspx
I like the architecture proposed, but I feel like it will have a greater impact on consumers of the API.
I'd personally wouldn't mind to switch to it, since in the project I'm working on we are barely starting to use the MessagingCenter, but if it were in a later stage and it was more intensely used, I'd be a bit reticent to change it.
New PR: https://github.com/xamarin/Xamarin.Forms/pull/723
Should be fixed in 2.3.5-pre1