lundi 19 septembre 2016

Mvx.Resolve fails in unit tests

I'm currently trying to write unit tests for an android/ios application written in xamaring using mvvmcross. I've followed the instructions in the wiki and they do work well to the point when a service tries to change the ViewModel this way:

var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
viewDispatcher?.ShowViewModel(
new MvxViewModelRequest(typeof(HomeViewModel), null, null, MvxRequestedBy.Unknown));

The tests fail at the first line with Mvx.Resolve();. I assume this is down to registering the interfaces in the mock IoC container:

this.mockDispatcher = new MockDispatcher();
this.Ioc.RegisterSingleton<IMvxViewDispatcher>(this.mockDispatcher);
this.Ioc.RegisterSingleton<IMvxMainThreadDispatcher(this.mockDispatcher);

so Mvx cannot resolve then when called this way. Can this code be tested or is there any other possibility to change the ViewModel from the service?

Aucun commentaire:

Enregistrer un commentaire