ref argument and It.Is<> (or It.IsAny<>)

1,349 views
Skip to first unread message

Lionel

unread,
Sep 24, 2010, 12:31:14 PM9/24/10
to Moq Discussions
Hi all,

Is there any way to call the Setup method with a byref argument and
It.Is<T> ?
If I have the method
Inherit(ref Group parentGroup, [...])
to have something like:
mymock.Setup(f => f.Inherit(ref It.IsAny<Group>(), [...]));

Pitifully, I cannot really know in advance the value of the byref
parameter, so I don't think I can do the Setup with an explicit value
(I know the variable name of course, but not its content).

Many thanks in advance
Lionel

Chris Missal

unread,
Sep 24, 2010, 3:35:08 PM9/24/10
to moq...@googlegroups.com
Is there any way to call the Setup method with a byref argument and It.Is<T>?

No, sorry. You need the actual instance that is going to be passed in for the match to occur.
 




--
Chris Missal
http://chrismissal.lostechies.com/

Daniel Cazzulino

unread,
Sep 24, 2010, 3:42:32 PM9/24/10
to moq...@googlegroups.com
ref arguments are not used for matching, they are used as return values.

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471

Lionel

unread,
Sep 27, 2010, 2:57:26 AM9/27/10
to moq...@googlegroups.com
Daniel,
 
Do you mean that the ref argument is not used when match a declaration (a Setup) against actual method calls?
 
Lionel
 
(Thks Chris also for your answer)


De : moq...@googlegroups.com [mailto:moq...@googlegroups.com] De la part de Daniel Cazzulino
Envoyé : vendredi 24 septembre 2010 21:43
À : moq...@googlegroups.com
Objet : Re: [Moq] ref argument and It.Is<> (or It.IsAny<>)

Daniel Cazzulino

unread,
Sep 27, 2010, 5:02:07 PM9/27/10
to moq...@googlegroups.com
indeed. ref/out are considered return values only.


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Reply all
Reply to author
Forward
0 new messages