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 ReceivedWithAnyArgs/DidNotReceiveWithAnyArgs misuse #174

Closed
rklec opened this issue Oct 28, 2021 · 0 comments · Fixed by #189
Closed

Detect ReceivedWithAnyArgs/DidNotReceiveWithAnyArgs misuse #174

rklec opened this issue Oct 28, 2021 · 0 comments · Fixed by #189
Labels
enhancement New feature or request
Milestone

Comments

@rklec
Copy link

rklec commented Oct 28, 2021

Could you detect invalid usages of ReceivedWithAnyArgs?

E.g.:

Wrong ReceivedWithAnyArgs usage with Arg.Is -> this will not be checked

public interface ITest
{
    void DoSomething(string? thing);
}

public class Test
{
    [Test]
    public void TestSth()
    {

        var test = Substitute.For<ITest>();
        test.DoSomething("else");
        test.ReceivedWithAnyArgs().DoSomething(Arg.Is<string>(x => x.Contains("wrong")));
        test.Received().DoSomething(Arg.Is<string>(x => x.Contains("wrong"))); // correct -> fails test
    }
}

Wrong DidNotReceiveWithAnyArgs usage with Arg.Is -> this will not be checked

        var test = Substitute.For<ITest>();
        test.DoSomething("this");
        test.DidNotReceive().DoSomething(Arg.Is<string>(x => x.Contains("that"))); // correct, does not fail test
        test.DidNotReceiveWithAnyArgs().DoSomething(Arg.Is<string>(x => x.Contains("that"))); // wrong, always fails
@tpodolak tpodolak added the enhancement New feature or request label Nov 12, 2021
tpodolak pushed a commit that referenced this issue Jun 5, 2022
tpodolak added a commit that referenced this issue Aug 14, 2022
tpodolak pushed a commit that referenced this issue Aug 14, 2022
First part of renaming

Second part of renaming

GH-174 - support for ThrowsAsync
tpodolak added a commit that referenced this issue Sep 9, 2022
GH-174 - analyzing usages of WithAnyArgs/ForAnyArgs like methods
@tpodolak tpodolak added this to the 1.0.16 milestone Jan 8, 2023
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

Successfully merging a pull request may close this issue.

2 participants