Click or drag to resize
EventRecorderT Class
An object that can be hooked to an event to determine that it has been raised and record the parameters passed to the event.
Inheritance Hierarchy
SystemObject
  Test.FrameworkEventRecorderT

Namespace: Test.Framework
Assembly: Test.Framework (in Test.Framework.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public class EventRecorder<T>
where T : EventArgs

Type Parameters

T

The EventRecorderT type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyAllArgs
Gets a list of every args parameter passed to the event. There will be CallCount entries in the list.
Public propertyAllSenders
Gets a list of every sender parameter passed to the event. There will be CallCount entries in the list.
Public propertyArgs
Gets the args parameter from the last time the event was raised.
Public propertyCallCount
Gets the number of times the event has been raised.
Public propertySender
Gets the sender parameter from the last time the event was raised.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleHandler
An event handler matching the EventHandler and/or EventHandler<> delegate that can be attached to an event and record the parameters passed by the code that raises the event.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnEventRaised
Raises EventRaised.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Events
  NameDescription
Public eventCode exampleEventRaised
Raised by Handler(Object, T) whenever the event is raised. Can be used to test the state of objects when the event was raised.
Top
Remarks
This only works with standard events that pass two parameters, a sender object and an args based on EventArgs.
Examples
public class ObjectUnderTest()
{
    public event EventHandler TheEvent;

    public void RaiseEvent()
    {
        if(TheEvent != null) TheEvent(this, EventArgs.Empty);
    }
}

[TestMethod]
public void Check_That_RaiseEvent_Raises_TheEvent()
{
    var objectUnderTest = new ObjectUnderTest();
    EventRecorder<EventArgs> eventRecorder = new EventRecorder<EventArgs>();

    objectUnderTest.TheEvent += eventRecorder.Handler;
    objectUnderTest.RaiseEvent();

    Assert.AreEqual(1, eventRecorder.CallCount);
    Assert.AreSame(objectUnderTest, eventRecorder.Sender);
    Assert.IsNotNull(eventRecorder.Args);
}
See Also