Hi,
This really depends on your code and how accessible the events are, and what you are testing.
:idea: A simple answer to your question is to use the DynamicReturnValue, you can then put any code you want in the delegate.
:idea: Of course if you are just trying to test how you code runs with events, it is better to just raise the event from within the test.
public void MyTestEventHandler(object sender, MyEventArgs e)
{
}
[Test]
public void TestRaiseEvent()
{
// Natural Mocks - expect one call of event handler
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
MyTestEventHandler(null,null); // don't care about arguments
}
TestObject theObject = new TestObject();
theObject.MyEvent += MyTestEventHandler;
theObject.MyEvent(this,new MyEventArgs());
// make sure that our method has been called
MockManager.Verify();
}
You can of course use a 'real' event handler method or write one just for the test.
The Reflective TypeMock equivalent is:
Mock theMock = MockManager.Mock(this.GetType());
theMock.ExpectCall("MyTestEventHandler");