Suppose you have an object called EventSource that has
a public event. Now you want to test that consumer of
the EventSource object - EventConsumer handles event
properly. Tricky part is to make EventSource to throw
an event during the test.
I have extended DynamicMock with RaiseEvent method:
public void RaiseEvent(string eventName, params object
[] args);
Upon call the method will call all the delegates that
were registered with the event. Under the hood dynamic
mock intercept calls to add_<event> and remove_<event>
methods and maintains the collection of event handlers
in a fashion similar to MulticastDelegate.
As usual limitation is that event has to be declared
public virtual.
It also works with interfaces.