Unit testing Windows Phone 7 MvvmLight-viewmodels with 7.1 sdk rc, NUnit and Moq

After a few hours of banging my head againt the wall, i finally bended this combo to my will. Humble thanks to J. Wilcox, J. Cansdale, W. McClure. Even humbler thank you goes to rschiefer for tipping me towards the version of Moq that worked in this scenario!

First up is getting the bits:

Strangely enough, f.ex. latest version of Moq doesn’t work. I got TypeLoadException while executing tests.

Next create projects:

  • Fire up Visual Studio
  • Create new MvvmLight WP7 -project (SUT-project)

  • Convert the SUT-project to WP 7.1

  • Create new Silverlight NUnit Project (Test project)

Add references to ext libs and between projects:

  • Reference Moq 3.1.416.3 to the Test project

  • Reference SUT-project to the Test project
  • Reference MvvmLight-libs to Test project
  • Build and check everything is sane

Add some code to test:

  • Add IConfiguration-interface
  • Pass IConfiguration to MainViewModel via constructor argument
  • Extract an interface from SUT-project’s MainViewModel

Add test method and execute:

  • Create a test

  • Execute and everything should work :-)

Advertisements

One thought on “Unit testing Windows Phone 7 MvvmLight-viewmodels with 7.1 sdk rc, NUnit and Moq

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s