[RhinoMocks] Verifying a single parameter

6 views
Skip to first unread message

Dan Ryan

unread,
May 17, 2010, 4:00:30 AM5/17/10
to Rhino.Mocks
Hi,

I am currently using the following code to verify a single parameter
input to a method. Is there a cleaner way to do this without needed
to supply Is.Any for the parameters I am not interested in?

[TestMethod]
public void ShouldCallTheAvanceServiceWithTheAValidGuid()
{
_sut.Send(_sampleInput);
_avanceInterface.AssertWasCalled(x => x.SendData(
Arg<Guid>.Is.Equal(Guid.Empty),
Arg<string>.Is.Anything,
Arg<string>.Is.Anything,
Arg<string>.Is.Anything,
Arg<string>.Is.Anything));
}

Thanks in advance,

Dan

--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.

Tim Barcz

unread,
May 20, 2010, 7:51:29 PM5/20/10
to rhino...@googlegroups.com
I believe this came up a long time ago...and the problem is that with lambdas you have to supply *something* for each parameter of the called method.

To that end...what you have is proper (as I recall).

Just to help allay your fears a bit...this verbosity isn't always a bad thing.  When I read the code, based on the syntax you have used I know that for this particular test no parameters matter except the first...extremely useful in my opinion.

Tim
--
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

Chris Missal

unread,
May 21, 2010, 12:21:33 PM5/21/10
to rhino...@googlegroups.com
I've run into this before and I have moved the assertion into my own extension method. So:

_avanceInterface.AssertWasCalled(x => x.SendData(
               Arg<Guid>.Is.Equal(Guid.Empty),
               Arg<string>.Is.Anything,
               Arg<string>.Is.Anything,
               Arg<string>.Is.Anything,
               Arg<string>.Is.Anything));

becomes:

_avanceInterface.AssertSendDataWasCalledWithEmptyGuid();

then use that extension method to encapsulate the above assertion. It's nice if you have to repeat that verbosity in more than one place. (and helps reduce the surface area when things change)


Reply all
Reply to author
Forward
0 new messages