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
ObservableObject
implementsINotifyPropertyChanged
RaisePropertyChangedEvent
with property name fires eventRaisePropertyChangedEvent
with property name passes name through to handlerRaisePropertyChangedEvent
with name of non-existent property throwsArgumentException
(in Debug only)RaisePropertyChangedEvent
with multiple property names fires event for eachRaisePropertyChangedEvent
with no observers does not throw exception
DelegateCommand : ICommand
DelegateCommand
implementsICommand
CanExecute
returnsTrue
Execute
runs storedAction
Execute
with 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