I am a "newbie" in TDD, and something I'm trying to understand is like unit test viewmodels ...
I want to make sure that the object's ProeprtyChanged event is fired ... I have the following test using nunit.
[Test]
public void Radius_Property_Changed()
{
var result = false;
var sut = new MainViewModel();
sut.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "Radius")
{
result = true;
}
};
sut.Radius = decimal.MaxValue;
Assert.That(result, Is.EqualTo(true));
}
Is this the cleanest way to do this, or is there a better way to test this property
... the code snippet in the viewmodel proti that I'm testing looks like this ...
public decimal Radius
{
get { return _radius; }
set
{
_radius = value;
OnPropertyChanged("Radius");
}
}
source
share