Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should throw on unused arg matchers #279

Closed
dtchepak opened this issue Jan 6, 2017 · 0 comments · Fixed by #361
Closed

Should throw on unused arg matchers #279

dtchepak opened this issue Jan 6, 2017 · 0 comments · Fixed by #361

Comments

@dtchepak
Copy link
Member

dtchepak commented Jan 6, 2017

In this example the problem occurs because int implicitly casts to double, but NSubstitute doesn't pick up the argument matcher as the types diff (changing that opens a can of worms IIRC). I think that that when Returns runs the "any int" matcher is discarded; instead it should throw as the call has not been specified correctly.

        public interface IFoo {
            int Blah(double s);
        }

        [Test]
        public void NSubRepro()
        {
            var foo = NSubstitute.Substitute.For<IFoo>();
            foo.Blah(Arg.Any<int>()).Returns(42);
            Assert.AreEqual(42, foo.Blah(10)); 
            /* FAILS: 
                  Expected: 42
                  But was:  0 */
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant