You know, maybe the "Do" extension method would work better for you in
this case (I often get those two mixed up).  Again, if I remember
correctly, the "Do" method takes a delegate which has to match the
signature of the method being stubbed so it's easier to plug in a
strongly-typed lambda.

And yes, the syntax is a little clunky, but you're stubbing a method
that has a return value so Rhino.Mocks requires you to define a
"Return" (even if its ignored).  The only way Rhino.Mocks would know
that a "WhenCalled" method sets a return value would be to parse the
code *inside* the lambda/delegate that WhenCalled executes.

Moq has the advantage of being newer and doesn't have to support an
older style/syntax that Rhino.Mocks does.  I still use both, but
currently I favor moq for it's simplicity.

---
Patrick Steele
http://weblogs.asp.net/psteele



On Wed, Sep 21, 2011 at 9:48 AM, Felix <[email protected]> wrote:
> Hi Patrick,
>
> That didn't work for me but for some reason this does:
>
>            myMock.Stub(e => e.MyMethod(Arg<string>.Is.Anything,
> Arg<int>.Is.Anything))
>                .Return(null)
>                .WhenCalled(a => a.ReturnValue =
> MyMethodLocalImplementation((string)a.Arguments[0],
> (int)a.Arguments[1]));
>
> As a Moq fanboi I find this pretty clunky :/
>
> On Sep 21, 1:58 pm, Patrick Steele <[email protected]> wrote:
>> Use "WhenCalled".
>>
>> myMock.Stub(x => x.SomeMethod()).WhenCalled(i => ...);
>>
>> IIRC, the lambda parameter "i" is a "MethodInvocation" that gives you
>> access to the method's arguments as well as setting a return value.
>>
>> ---
>> Patrick Steelehttp://weblogs.asp.net/psteele
>>
>>
>>
>>
>>
>>
>>
>> On Wed, Sep 21, 2011 at 8:31 AM, Felix <[email protected]> wrote:
>> > Hi,
>>
>> > using Moq I would do this:
>>
>> >            myMock.Setup(x => x.MyMethod(It.IsAny<string>(),
>> > It.IsAny<int>())).Returns(
>> >               (string str, int num) =>
>> > MyMethodLocalImplementation(str, num));
>>
>> > to implement one method of my stub locally. How can this be done in
>> > Rhino?
>>
>> > Thanks for any help.
>> > felix
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Rhino.Mocks" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to 
>> > [email protected].
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/rhinomocks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rhinomocks?hl=en.
>
>

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

Reply via email to