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

Ambiguous args with out/ref arg #129

Closed
dtchepak opened this issue Jan 6, 2014 · 5 comments
Closed

Ambiguous args with out/ref arg #129

dtchepak opened this issue Jan 6, 2014 · 5 comments

Comments

@dtchepak
Copy link
Member

dtchepak commented Jan 6, 2014

Broken in 1.7. From #111 or #114?

Example from Google Group:

    [TestFixture]
    public class TestFixture
    {
        public interface ITestInterface
        {
            bool DoStuff(string input);
            bool DoStuff(string input, out string output);
        }

        [Test]
        public void Test()
        {
            string someType;
            var substitute = Substitute.For<ITestInterface>();
            substitute.DoStuff(Arg.Any<string>(), out someType).ReturnsForAnyArgs(info =>
                {
                    info[1] = "test";
                    return true;
                });
        }
    }
/*
NSubstitute.Exceptions.AmbiguousArgumentsException : Cannot determine argument specifications to use.
Please use specifications for all arguments of the same type.
   at NSubstitute.Core.Arguments.NonParamsArgumentSpecificationFactory.Create(Object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) in NonParamsArgumentSpecificationFactory.cs: line 26
   at NSubstitute.Core.Arguments.ArgumentSpecificationFactory.Create(Object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) in ArgumentSpecificationFactory.cs: line 25
*/
alexandrnikitin added a commit to alexandrnikitin/NSubstitute that referenced this issue Jan 12, 2014
Fixed by adding IsOut ParameterType exception to NonParamsArgumentSpecificationFactory
@dtchepak
Copy link
Member Author

Fixed in 1.7.1. Thanks Alexandr!

@dabide
Copy link

dabide commented Mar 28, 2014

The fix seems only to work with out, not with ref. http://stackoverflow.com/questions/1551761/ref-parameters-and-reflection

@alexandrnikitin
Copy link
Member

It's not so obvious with ref variables. How to treat them? As "match any" like out arguments? How to specify exact argument? Using workaround? If so, then it's pretty easy fix. I think we need @dtchepak's input here.

@dtchepak
Copy link
Member Author

dtchepak commented Apr 3, 2014

@alexandrnikitin At first guess I'd match on ref value.

string x = "x";
sub.Stuff(ref x).Returns(info => { info[0] = "hi"; return true; });

sub.Stuff(x);
Assert.AreEqual("hi", x);
x = "something else";
sub.Stuff(x); // this call doesn't match the call spec, so `x` is not set to "hi"
Assert.NotEqual("hi", x); // 

Sound ok?

@alexandrnikitin
Copy link
Member

I'm fine with it. This behavior is more comprehensible and logical than "match any".

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

No branches or pull requests

3 participants