I would like to stub a property on a mock object, and have an event fired whenever my test calls the setter for that property. Something like the following. Given:
public interface ISomething
{
event Action FooChanged;
int Foo { get; set; }
}
I would like to have a test like this (and of course this does not compile):
[Test]
public void HandleChangeInDependencyObject()
{
var mock = new Mock<ISomething>();
mock.SetupProperty(m => m.Foo).Raises(m => m.FooChanged += null);
mock.Object.Foo = 5; // raises the FooChanged event on ISomething
...
}
Is this possible with Moq? All I could find was a post from 2009 on a Google Groups forum discussing it.