Rhino Mocks 2.7: Events
I finally got rid of the coding block, and I think I compensated by a large degree. Rhino Mocks has a new and improve version, including:
- Support for raising events
- Improved support for remoting mocks
- Fixed a bug with regard to interfaces with the same name on different namespaces.
Check out the events:
IEventRaiser raiser;
[Test]
public void RaiseEvent()
{
IWithEvents eventHolder = (IWithEvents)mocks.CreateMock(typeof(IWithEvents));
eventHolder.Blah += null;
LastCall.IgnoreArguments();
raiser = LastCall.GetEventRaiser();
eventHolder.RaiseEvent();
LastCall.Do(new System.Threading.ThreadStart(UseEventRaiser));
IEventSubscriber eventSubscriber = (IEventSubscriber)mocks.CreateMock(typeof(IEventSubscriber));
eventSubscriber.Hanlder(this, EventArgs.Empty);
mocks.ReplayAll();
eventHolder.Blah += eventSubscriber.Hanlder;
eventHolder.RaiseEvent();
mocks.VerifyAll();
}
private void UseEventRaiser()
{
raiser.Raise(this, EventArgs.Empty);
}
The eventHolder.Blah += null syntax is something that I am forced to do because of the language constraint (C# doesn't allow to do anything to an event except subscribe / un-subscribe to it).
You can check it out here (sources and binaries, of course).
Comments
Comment preview