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

Add info to AmbiguousArgumentsException #262

Closed
dtchepak opened this issue Nov 19, 2016 · 4 comments
Closed

Add info to AmbiguousArgumentsException #262

dtchepak opened this issue Nov 19, 2016 · 4 comments

Comments

@dtchepak
Copy link
Member

From 260, would be useful to put info on what call is being run in AmbiguousArgumentsException, and also the arg matchers available vs. provided arguments (to narrow down what is ambiguous).

@roryprimrose
Copy link

I hit this problem because other tests in the class were substituting an extension method (part of a refactor). This error went away once I fixed up the substitutions.

Perhaps there needs to be some validation on the substitution request to validate that the member can be stubbed out. Should a separate issue be raised for this?

Another potential change (related to this issue) is to indicate in the exception message that other incorrect substitutions in the test run may be causing this issue.

@dtchepak
Copy link
Member Author

Hi @roryprimrose,
If I understand what you mean correctly, I don't think this is possible with NSub. The incorrect substitutions are only incorrect because NSub can't detect them (otherwise we would have the hooks to handle it properly).

If I've misunderstood or if you have some ideas on how we can detect these cases please let me know. :)

@roryprimrose
Copy link

Thanks @dtchepak

I tried to simulate this scenario but the error I got actually gave a good error message.

namespace ConsoleApp1
{
    using NSubstitute;

    class Program
    {
        static void Main(string[] args)
        {
            var target = Substitute.For<Stuff>();

            target.DoSomething().Returns(123);
        }
    }

    public static class Extensions
    {
        public static int DoSomething(this Stuff stuff)
        {
            return 1;
        }
    }

    public class Stuff
    {
        public string Value
        {
            get;
            set;
        }
    }
}

I don't understand why this code produces the nice failure from NSub but my more complex scenario didn't. Perhaps it was that there was a suite of tests being executed and that incorrect tests caused the others to fail. Either way, the linked issue helped me to figure out that I needed to fix the tests broken by my refactor to remove the problem.

At this stage I would say just ignore my previous comment :)

Thanks for the quick response.

@dtchepak
Copy link
Member Author

dtchepak commented Oct 6, 2017

Closing as part of a general cleanup of blocked issues. Please re-open if more information comes to light which will let us proceed with this.

@dtchepak dtchepak closed this as completed Oct 6, 2017
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

2 participants