I have a method that accepts an IEnumerable
:
MyMethod(IEnumerable<MyClass> myParameter)
Now I am writing this code to mock the service:
var array1 = new MyClass[0];
var array2 = new MyClass[0];
_service
.Setup(s => s.MyMethod(array1))
.Returns(value1);
_service
.Setup(s => s.MyMethod(array2))
.Returns(value2);
And finally I am doing two calls to the service with both arrays inside system under test:
_service.MyMethod(array1);
_service.MyMethod(array2);
What I do expect is to get value1
and value2
from these calls, but in practice the latter call overrides the first one and I only get value2
from both calls.
Is this a bug in Moq or is this a feature that setup treats IEnumerable
not as a separate object but rather tries to expand it and compare all elements or something (resulting in two empty arrays being the same setup call)?