Menu

#25 RaiseEvent feature

open
5
2013-01-10
2005-11-24
rgavrilov
No

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.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.