Unit testing the bootstrapper and modules

Topics: Prism v4 - WPF 4
Nov 17, 2010 at 1:52 PM

Hello to all,

I've started writing an application with prism v4 and I'm trying to unit test my bootstrapper. The problem is that my app.current is null and that cause an error in my code. Also, when I try to call code from a module, when it tries to register a view with a region, it also cause an error because it's not present.

Should I mock everything or is there a nice and clean way to go through that?

I'm using TypeMock as a mocking framework and Unity.

Thanks!

Jonathan

Nov 17, 2010 at 8:43 PM

Hi Jonathan,

Nice to see that you started using Prism 4. First of all, take into account that the product team is using Moq to create its mock objects. That said, there is no guidance about how to mock the Application.Current in Prism out-of-the-box. I assume that you are trying to test the following method:

protected override void InitializeShell()
{
base.InitializeShell();

#if SILVERLIGHT
Application.Current.RootVisual = (Shell)this.Shell;
#else
Application.Current.MainWindow = (Shell)this.Shell;
Application.Current.MainWindow.Show();
#endif
}

In the Prism Library the base.InitializedShell method has already been tested. That said, I am not sure whether the override method in your Bootstrapper should be tested or not, as it contains reference to static classes. A possible solution for testing this could be create a CodeUI test.

Regarding to test the registration of views in regions, it is something tested in the PrismLibrary, so this might be solved by creating a mock of the IRegionManager/IRegion. You can check similar tests on the StockTraderRI.

Hope this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero