You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public interface IFoo
{
int Read(int i);
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var foo = Substitute.For<IFoo>();
foo.Read(Arg.Is<int>(x => x == 0)).Returns(0, 1, 2);
foo.Read(Arg.Is<int>(x => x == 1)).Returns(3, 4, 5);
Assert.AreEqual(0, foo.Read(0));
Assert.AreEqual(3, foo.Read(1));
Assert.AreEqual(1, foo.Read(0));
Assert.AreEqual(4, foo.Read(1));
Assert.AreEqual(2, foo.Read(0));
Assert.AreEqual(5, foo.Read(1));
}
}
The problem is that the first Assert incorrectly fails, because the first call to Read(0) returns 1, instead of 0. I can reproduce this consistently and this is the most concise reproducer I could come up with.
The text was updated successfully, but these errors were encountered:
The problem is that the second stub foo.Read(Arg.Is<int>(x => x == 1)) will actually call foo.Read(0) and cause the first of 0, 1, 2 to be returned. (I think it would work correctly if the conditions where ==1 and ==2 as it would filter out the 0 case.)
You could try working around the issue by specifying the ==1 case first:
[TestMethod]
public void TestMethod1()
{
var foo = Substitute.For<IFoo>();
foo.Read(Arg.Is<int>(x => x == 1)).Returns(3, 4, 5);
foo.Read(Arg.Is<int>(x => x == 0)).Returns(0, 1, 2);
...
Fix notes
There is an issue with fixing this: currently the record call route returns the configured result so we can chain calls. So fixing this would break that behaviour. One option would be to not return the configured result for value types.
The problem is that the first Assert incorrectly fails, because the first call to Read(0) returns 1, instead of 0. I can reproduce this consistently and this is the most concise reproducer I could come up with.
The text was updated successfully, but these errors were encountered: