Ayende @ Rahien

Unnatural acts on source code

Rhino Mocks Events: Twisting the Syntax

Okay, so Aaron Jensen has suggest an alternative syntax to this (which I don't like, since it has strings):

IEventRaiser loadRaiser = new EventRaiser((IMockedObject)mockedView, "Load");

It is this:

obj.Bar += EventRaiser.Raise(this, EventArgs.Empty);

Basically, it is reversing the syntax a bit, since it is actually the "register to event" syntax, but we can use that to raise events in a fairly natural way, without resorting to strings.

I am not sure if the sytnax is clear enough, so I wanted to ask, what would you rather have?

Comments

Roy Osherove
06/09/2007 09:18 AM by
Roy Osherove

Isn't it possible to do EventRaiser.GetRaiser(obj.Bar)? where GetRaiser takes in a MultiCast Delegate?

Ayende Rahien
06/09/2007 10:33 AM by
Ayende Rahien

Roy,

Much as I would like it to be this way, the compiler will give an error on this code.

Ayende Rahien
06/09/2007 10:41 AM by
Ayende Rahien

Roy,

Much as I would like it to be this way, the compiler will give an error on this code.

Ayende Rahien
06/09/2007 10:41 AM by
Ayende Rahien

Roy,

Much as I would like it to be this way, the compiler will give an error on this code.

Ayende Rahien
06/09/2007 10:41 AM by
Ayende Rahien

Roy,

Much as I would like it to be this way, the compiler will give an error on this code.

Adam Dymitruk
06/10/2007 08:46 PM by
Adam Dymitruk

Another annoyance that some people raise is having to hook up a null to the rest of the events, even the ones that we are not interested in.

Shaun Cartwright
06/11/2007 09:02 AM by
Shaun Cartwright

Sorry Ayende, I was referring to the comment by @Adam. Complaining about having to wire up the expectation of handling other events to null. I believe it was a comment to the mocking framework in general. The solution to this, of course, is to use dynamic mocks to setup expectations to the specific test case in hand.

Comments have been closed on this topic.