Click or drag to resize
EventRecorderTEventRaised Event
Raised by Handler(Object, T) whenever the event is raised. Can be used to test the state of objects when the event was raised.

Namespace: Test.Framework
Assembly: Test.Framework (in Test.Framework.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public event EventHandler<T> EventRaised

Value

Type: SystemEventHandlerT
Remarks
The sender passed to the event is the EventRecorder, not the sender of the original event. By the time the event is raised the EventRecorder's Sender property will be set to the sender of the original event.
Examples
This snippet shows how to check the state of an object when the event is raised. In this case it is testing that when some hypothetical object raises CountChanged its Count property is set to 2.
EventRecorder<SomeArgs> eventRecorder = new EventRecorder<SomeArgs>();
myObject.CountChanged += eventRecorder.Handler;
recorder.EventRaised += (s, a) => { Assert.AreEqual(2, myObject.Count); };

myObject.DoSomeWork();

Assert.AreEqual(1, recorder.CallCount);
Similarly this code will test what happens when an event handler throws an exception during processing:
EventRecorder<SomeArgs> eventRecorder = new EventRecorder<SomeArgs>();
myObject.CountChanged += eventRecorder.Handler;
recorder.EventRaised += (s, a) => { throw new InvalidOperation(); };

myObject.DoSomeWork();
Finally, this code checks that the sender is the same as the myObject value during processing of the event. Note that the sender passed to the event is the EventRecorder that is raising the event, not the original sender, so the test must use the EventRecorder's Sender property.
EventRecorder<SomeArgs> eventRecorder = new EventRecorder<SomeArgs>();
myObject.CountChanged += eventRecorder.Handler;
recorder.EventRaised += (s, a) => {
    // This just illustrates that the sender is the EventRecorder and to get the original
    // sender you need to use the appropriate property on the event recorder.
    Assert.AreSame(s, eventRecorder);
    Assert.AreSame(eventRecorder.Sender, myObject);
};
See Also