Prism – RegionManager ready for Unit-Tests

You are using Prism for navigation and region management of your application. Be it WPF, Silverligh, Windows Apps, etc.

In any kind of application you will need to work with prism ultimate wappon for navigation and region management – IRegionManager interface.

But how can you test your Modules, ViewModels and any kind of logic which is used to handle navigation or region management. ‚IRegionManager‘ interface is a little bit tricky because many methods are implemented as extension methods. And extension methods can not be mocked by any unit test framework out there.

But there is a pretty simple solution for this problem: ‚Adapter Design Pattern‘. Take a look at a possible solution:

Now all you need to write your unit-tests is to mock ‚IMyRegionManager‘. If you need to mock much more extension methods just add them to YOUR interface and implement an adapter method for the extension method of ‚IRegionManager‘.

Schreib einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *