Tailspin uses the Silverlight unit test framework for Windows Phone 7 and Silverlight 3 that’s described in Appendix A, “Tools, Frameworks, and Processes.”
The Windows Phone 7 project named Tailspin.PhoneClient.Tests contains the unit tests for the Surveys mobile client application. To run the tests, first build and then deploy this project either to the Windows Phone 7 emulator or to a real device. On the Windows Phone 7 device, you can now launch an application named Tailspin. PhoneClient.Tests, and then select the unit tests you want to run.
The following code example shows a unit test method from the SurveyListViewModelFixture class that tests that the view model returns a list of all the surveys that are marked as favorites.
C#
[TestMethod]
public void FavoritesSectionShowsFavoritedItems()
{
var store = new SurveyStoreMock();
var surveyStoreLocator = new SurveyStoreLocatorMock(store);
store.Initialize();
var allSurveys = store.GetSurveyTemplates();
var vm = new SurveyListViewModel(surveyStoreLocator,
new SurveysSynchronizationServiceMock());
vm.Refresh();
var favoriteSurveys =
vm.FavoriteItems.Cast<SurveyTemplateViewModel>().ToList();
CollectionAssert.AreEquivalent(
allSurveys.Where(p => p.IsFavorite).ToArray(),
favoriteSurveys.Select(t => t.Template).ToArray());
}
This method first instantiates a mock survey store and store locator objects to use in the test. The method then instantiates the view model object from the Tailspin.PhoneClient project to test, passing in the mock store locator object. The method then executes the test on the view model instance and verifies that the favorite surveys in the view are the same as the ones in the underlying database.