-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
I wanted to check the number of times RaisePropertyChanged had been raised for a particular property.
I expected to type:
myVm.ShouldRaisePropertyChangedFor(vm => vm.myProperty).Count().ShouldBeEquivalentTo(2);This failed - the count returned was for ALL RaisePropertyChange events, not the specific one I am testing.
I have written a quick extension method:
public static int SpecificRaisePropertyChangedCount(this IEnumerable<RecordedEvent> value, string propertyName)
{
return value.Select(r => r.Parameters)
.SelectMany(s => s)
.Count(p => p is PropertyChangedEventArgs && (p as PropertyChangedEventArgs).PropertyName == propertyName);
}so you can now do:
myVm.ShouldRaisePropertyChangedFor(vm => vm.myProperty)
.SpecificRaisePropertyChangedCount(nameof(myVm.myProperty))
.ShouldBeEquivalentTo(2);Sorry I haven't submitted this as a pull request - I'm up to my neck in it and no time to clone the repo etc, but feel free to add it or whatever (or tell me that I could have done it with the existing code easily ^_^ )