Skip to content

Instantly share code, notes, and snippets.

@hartbit
Created September 23, 2013 15:05
Show Gist options
  • Save hartbit/6671807 to your computer and use it in GitHub Desktop.
Save hartbit/6671807 to your computer and use it in GitHub Desktop.
[Test]
public void SimpleTest()
{
var calculator = Substitute.For<ICalculator>();
int z;
calculator.Add(1, 2, out z).Returns(x => { x[2] = 2; return 3; });
calculator.Add(4, 5, out z).Returns(x => { x[2] = 20; return 9; });
Expect(calculator.Add(1, 2, out z), Is.EqualTo(3));
Expect(z, Is.EqualTo(2));
Expect(calculator.Add(4, 5, out z), Is.EqualTo(9)); // Expected 9 but was 0
Expect(z, Is.EqualTo(20));
}
@dtchepak
Copy link

This is a known issue. Problem is that Add(4,5,z) is configured when z=0 (its default value). Then during the test, Add(1,2,z) sets z=2, and the next call is Add(4,5,out 2), which is not configured. If you add z=0; to line 12 the test should pass.

@hartbit
Copy link
Author

hartbit commented Sep 23, 2013

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment