chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
The examples I've seen of mocking events use events that are generated by an instance of a class. But in my application I have a number of derived classes that all need to raise events that a View class can subscribe to. So I have a static event in the base class that's raised from each derived classes and is declared as follows:

public static event EventHandler MyEvent;

Then the View class subscribes to this event as follows:

BaseClass.MyEvent += OnMyEvent;

Can I use TypeMock to test if this event been raised by a derived class operation?
asked by denisv (2.8k points)

1 Answer

0 votes
You have a few ways to make sure that an event was called:
1. Fake/Mock the event handler and verifiy it was called:

Isolate.Verify.WasCalledWithAnyArguments(() => MyClass.OnMyEvent);            Isolate.Verify.NonPublic.WasCalled(typeof(MyClass), "OnMyEvent");

2. Attach a new event handler and make sure it get called (this solution doesn't use Isolator)

3. You can have a look on examples (they use instances but should work with static events as well) at ... tural.html
answered by dhelper (11.9k points)