damirarh / damirscorner-utterances

utteranc.es comments for https://damirscorner.com
0 stars 0 forks source link

/blog/posts/20140616-UnitTestingNavigationInMvvmCross.html #20

Open damirarh opened 1 year ago

damirarh commented 1 year ago

Imported

URL: https://www.damirscorner.com/blog/posts/20140616-UnitTestingNavigationInMvvmCross.html

damirarh commented 1 year ago

Imported comment written by James Lavery on 2018-10-15T09:58:42

Although this post is over 4 years old, it's still very useful!

I have a couple of questions though:
* How are you setting up your ViewModel with regard to injecting the navigation service?
* Is NavigationCommand must be using the Navigation service - so is this being mocked? Or is the call to the Navigation service being intercepted by the MockDispatcher?

damirarh commented 1 year ago

Imported comment written by Damir Arh on 2018-10-20T06:35:35

I don't remember the details after all this time, but I took another look at the project I based the blogpost on.

As far as I can see, there's no direct interaction with navigation service in my code. All the navigation is implemented by calling ShowViewModel method on the MvxViewModel base class of all my view models. It is implemented in the MvxNavigatingObject base class.

Here's an example of a command definition:


PlayersEditorCommand = new MvxCommand(() => ShowViewModel<playerseditorviewmodel>());

The ShowViewModel method implementation must be obtaining the instance of the MockDispatcher using Ioc when it requests IMvxViewDispatcher. That's why the navigation calls are intercepted by that class and I can then verify which were made.