Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Removing the 'delegate' noise with RhinoMocks 3.5

As you may be aware Ayende has recently released Rhino 3.5 Release Candidate. Among many of the great improvements to this release, he as simplified the code needed to mock void methods.

Lets take a look at the older syntax:
Expect.Call(delegate { mockSession.Login("", ""); }).IgnoreArguments().Repeat.Once();

Lets now take a look at the new syntax:
mockSession.Expect( x => x.Login( "", "" ) ).IgnoreArguments().Repeat.Once();

Both ways will accomplish the same goal, but I know that I always hated having to use a delegate to set expectations on a void method.  To me the new syntax (using Lambda's) is much cleaner and flows off my keyboard much easier.

+1 for all Ayende's hard work

Till next time,

[----- Remember to check out DimeCasts.Net -----]

Posted 06-30-2008 8:28 AM by Derik Whittaker



Christopher Bennage wrote re: Removing the 'delegate' noise with RhinoMocks 3.5
on 06-30-2008 9:54 AM

Very nice.

Davy Brion wrote re: Removing the 'delegate' noise with RhinoMocks 3.5
on 06-30-2008 10:28 AM

the new syntax is definitely nice, but you could also do Expect.Call(() => myObject.MyVoidMethod()) with the previous version

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)