Posted by Mark Withall: 2013-08-06
Just out of interest, I was experimenting with TDDing (if that’s a real phrase) a basic MVVM framework in C#. The following is the rough sequence of tests for test-driving the implementation that I ended up using.
WPF makes use of two main interfaces: INotifyPropertyChanged for notifying the UI of updates to properties that it is bound to, e.g. the value in a TextBox; and ICommand for executing commands when, e.g. a Button is pressed.
Here are the sequence of tests for the two main classes in the framework.
ObservableObject : INotifyPropertyChanged
ObservableObjectimplementsINotifyPropertyChangedRaisePropertyChangedEventwith property name fires eventRaisePropertyChangedEventwith property name passes name through to handlerRaisePropertyChangedEventwith name of non-existent property throwsArgumentException(in Debug only)RaisePropertyChangedEventwith multiple property names fires event for eachRaisePropertyChangedEventwith no observers does not throw exception
DelegateCommand : ICommand
DelegateCommandimplementsICommandCanExecutereturnsTrueExecuteruns storedActionExecutewith null does not throw exception
I’m unsure as to the necessity of testing that the classes implement the required interfaces but it is technically a requirement of the implementation.
At some point in the near future, I hope to record a video of this development.
Tweet Follow @MarkWithall