Unable to set It.IsAny in ref attribute

327 views
Skip to first unread message

David Preti

unread,
May 1, 2012, 7:49:43 AM5/1/12
to moq...@googlegroups.com
Hi all,

I'm trying to set a ref attribute in a method of a mocked object.
I've a SaveUsers method which take a List<User> by ref. I want to setup the call back for every call I have on this method, doesn't matter the value of the List. So here is what I've written :

 var isAny = It.IsAny<List<User>>();
            this._helper.AdministrationServiceMock.Setup(a=>a.SaveUsers(ref isAny)).Callback()

But callback never execute, I've try to verify the call, but never called. 
Sure I miss something but don't see it.

Thanks for your help.


Daniel Cazzulino

unread,
May 1, 2012, 1:20:45 PM5/1/12
to moq...@googlegroups.com
Ref matching means that the setup is matched only if the method is called with that same instance. It.IsAny returns null, so probably not what you're looking for.

Use the same instance in the setup as the one in the actual call, and the setup will match.

/kzu

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


Reply all
Reply to author
Forward
0 new messages