The ViewDispatcher
is cached in the MvxMainThreadDispatcher.Instance
reference as an optimization (and also because of some legacy reasons).
However, it's still also registered in the IOC system too.
To use it in unit tests, the simplest route is to use a mock dispatcher like that in the n29 MvvmCross video - https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/blob/master/N-29-TipCalcTest/TipCalcTest.Tests/MockDispatcher.cs
This singleton is created and registered using code like:
var mockDispatcher = new MockDispatcher();
Ioc.RegisterSingleton<IMvxViewDispatcher>(mockDispatcher);
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(mockDispatcher);
and can be cleared within tests using ClearAll()
on MvxIoCSupportingTest
if you think this should be cleaned up in future Mvx versions, there is an open issue on https://github.com/MvvmCross/MvvmCross/issues/542 - people can comment and contribute there