Hello everyone.
I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
public bool EditModeEnabled
{
get { return _EditModeEnabled; }
set
{
_ModeEditModeEnabled = value;
OnPropertyChanged("EditModeEnabled");
OnPropertyChanged("CommentTextBoxVisibility");
}
}
OnPropertyChanged
is virtual method of base class which just raise PropertyChanged
event.
I want to test PropertyChanged
event raising and there my test method:
public void EditModeEnabledTest()
{
var imageViewModel = TestHelper.GetTestImageViewModel();
var firedEvents = new List<string>();
imageViewModel.PropertyChanged += ((sender, e) => firedEvents.Add(e.PropertyName));
imageViewModel.Mode = true;
Assert.AreEqual(firedEvents.Count, 2);
Assert.IsTrue(firedEvents.Contains("EditModeEnabled"));
Assert.IsTrue(firedEvents.Contains("CommentTextBoxVisibility"));
...
}
Is it a good way to test ProprtyChanged event?