How to match several arguments?

Skip to first unread message


Jun 12, 2017, 5:58:32 PM6/12/17
to Moq Discussions
I have a such line:
Mock.Get( map )
.Setup( i => i.GetItem( It.IsAny<int>(), It.IsAny<int>() ) )
.Returns<int, int>( (x, y) => itemCoords.Contains( new Vector2i( x, y ) ) ? item : null );

I want to move "itemCoords.Contains( new Vector2i( x, y ) )" into Setup part. But I can match x, y only separately.
is there a way to match x, y together? Or convert x, y into one Vector2i and match this vector?


Jun 12, 2017, 7:41:34 PM6/12/17
Without too much background, I'm not sure why you need that complexity. Your test should be good enough with one or 2 specific coordinates, so setup for them instead.

.Setup ( i=>i.GetItem( 1, 2 )).Returns(new Vector2i(1,2)), etc.
With loose mocks, if you do not set something upfront, it'll return to handle the rest of the cases.

If the above does not work for you, paste the whole test.

You received this message because you are subscribed to the Google Groups "Moq Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Svetoslav Milenov (Sunny)

Artificial Intelligence is no match for natural stupidity.


Jun 14, 2017, 12:52:00 PM6/14/17
to Moq Discussions
I rewrote to this:

foreach (var i in items) {
.Setup( x => x.GetItem( i.x, i.y ) ).Returns<int, int>( (x, y) => item );

But I'm not sure it's worse or better.
As I understand there is no way to match a few arguments at a time?
Reply all
Reply to author
0 new messages