Currently I’m doing a lot of WPF, we’re profound users of the MVVM pattern. I therefore often find myself writing a lot of unit tests for viewmodels. A, or maybe the, key feature of the MVVM pattern is the property binding between the view and the viewmodel. Once assigned a value to a property, the viewmodel notifies the view, who updates the view accordingly. A viewmodel might have a significant amount of properties who can notify the view with updates, therefore I’ve implemented two small extension methods for this purpose:

Copy to Clipboard

These extension methods can be used in several verification test contexts. The obvious one would be:

Copy to Clipboard

In this test I verify that the property named Property is raising its PropertyChanged event, when the setter is called with the string value “new string”. Clean and easy verification of properties on view models. These extension methods can participate in more complex test scenarios:

Copy to Clipboard

In this test I verify that the Property is raising the event, whenever another property setter is called.

Combining ShouldNotifyOn with combinations of the ShouldNotNotifyOn makes these two small extension methods quite handy when testing and verifying properties on view models.

Recent Posts