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.FrameworkAssembly: Test.Framework (in Test.Framework.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax public event EventHandler<T> EventRaised
Public Event EventRaised As EventHandler(Of T)
public:
event EventHandler<T>^ EventRaised {
void add (EventHandler<T>^ value);
void remove (EventHandler<T>^ value);
}
member EventRaised : IEvent<EventHandler<'T>,
'T>
Value
Type:
SystemEventHandlerTRemarks
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) => {
Assert.AreSame(s, eventRecorder);
Assert.AreSame(eventRecorder.Sender, myObject);
};
See Also