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

Incorrect NS4000 when using typeof expression #71

Closed
samcragg opened this issue Feb 19, 2019 · 4 comments
Closed

Incorrect NS4000 when using typeof expression #71

samcragg opened this issue Feb 19, 2019 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@samcragg
Copy link

I think the analyzer is incorrectly firing NS4000: Returns() is set with a method that itself calls Returns for the following code (this is the simplest I could get the code to reproduce the warning I was getting):

public interface IExample
{
    object Method();
}

public class ExampleTest
{
    [Fact]
    public void TypeofTestClass()
    {
        IExample example = Substitute.For<IExample>();
        example.Method().Returns(typeof(ExampleTest));
        //                       ^^^^^^^^^^^^^^^^^^^
    }
}

This is under dotnet-core 2.1 with using NSubstitute version 4.0.0, NSubstitute.Analyzers.CSharp version 1.0.5 and xunit version 2.4.1

Granted, the above code doesn't look realistic (there's no asserts!), however, I was getting the warning in one of my actual tests and it seems to be the typeof(TheClassContainingTheTest) that triggers it.

Let me know if there's anything I can do to help.

@tpodolak
Copy link
Member

@samcragg thanks for reporting, this one for sure is a bug. Fix is waiting for review

dtchepak pushed a commit that referenced this issue Feb 19, 2019
@tpodolak
Copy link
Member

@samcragg fix will be available in next release

@tpodolak
Copy link
Member

@samcragg released in 1.0.6

@samcragg
Copy link
Author

Just to confirm that's fixed it, thanks - that was an amazingly quick turnaround!

@tpodolak tpodolak modified the milestones: 1.0.7, 1.0.6 Mar 15, 2019
@tpodolak tpodolak added this to the 1.0.6 milestone Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants