How to match several arguments?

44 views
Skip to first unread message

Deni35

unread,
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?

Sunny

unread,
Jun 12, 2017, 7:41:34 PM6/12/17
to moq...@googlegroups.com
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.

--
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-unsubscribe@googlegroups.com
---
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 moqdisc+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Svetoslav Milenov (Sunny)

Artificial Intelligence is no match for natural stupidity.

Deni35

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

foreach (var i in items) {
   mock
.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
Forward
0 new messages