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

Detect non-virtual When...Do calls #18

Closed
tpodolak opened this issue Jun 30, 2018 · 0 comments
Closed

Detect non-virtual When...Do calls #18

tpodolak opened this issue Jun 30, 2018 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@tpodolak
Copy link
Member

Analyzers should be able to detect following wrong usages

using NSubstitute;

namespace MyNamespace
{
    public class Foo
    {
        public int Bar()
        {
            return 2;
        }
    }

    public class FooTests
    {
        public void Test()
        {
            int i = 0;
            var substitute = NSubstitute.Substitute.For<Foo>();

            void SubstituteCall(Foo sub)
            {
                sub.Bar();
            }

            substitute.When(SubstituteCall).Do(callInfo => i++);
            substitute.When(delegate(Foo sub) { sub.Bar() })
            substitute.When(sub => sub.Bar())
        }
    }
}

and of course usages of beforementioned examples executed as ordinal method and used with WhenForAnyArgs

@tpodolak tpodolak added the enhancement New feature or request label Jun 30, 2018
@tpodolak tpodolak self-assigned this Jun 30, 2018
tpodolak added a commit that referenced this issue Jul 1, 2018
tpodolak added a commit that referenced this issue Jul 1, 2018
@tpodolak tpodolak added this to the 0.1.0-beta2 milestone Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant