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?

Print | posted on Saturday, June 09, 2007 6:48 AM

Feedback


# Re: Rhino Mocks Events: Twisting the Syntax 6/9/2007 12:18 PM Roy Osherove

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


Gravatar

# re: Rhino Mocks Events: Twisting the Syntax 6/9/2007 1:33 PM Ayende Rahien

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


Gravatar

 re: Rhino Mocks Events: Twisting the Syntax 6/10/2007 11:46 PM 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.


Gravatar

 re: Rhino Mocks Events: Twisting the Syntax 6/11/2007 10:47 AM Shaun Cartwright

That's what dynamic mocks are for.


Gravatar

# re: Rhino Mocks Events: Twisting the Syntax 6/11/2007 11:45 AM Ayende Rahien

Can you explain it again?


Gravatar

 re: Rhino Mocks Events: Twisting the Syntax 6/11/2007 12:02 PM 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.