TDD: Helper for checking PropertyChanged event gets raised
Today I am working on my first WPF app, using the WPF Model-View-ViewModel (MVVM) Toolkit. Naturally, we are using TDD -- like ASP.NET MVC, WPF ViewModels and ICommands lend themselves very nicely to unit testing, even around difficult dependencies like OpenFileDialog.
Anyway, one problem I am seeing repeated is writing tests for PropertyChanged events firing at the correct time. This is required so that WPF views can display updated values when something changes. For a test helper, I wrote a quick disposable event listener and extension method for this:
An assertion will fail if the PropertyChanged event does not fire with the correct property name. Here is the extension method:
... and the event listener:
It's not fancy, and it's probably not thread-safe, but it does the trick for our app.