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

NS4000 Unexpected warning in foreach loop #93

Closed
appel1 opened this issue Apr 15, 2019 · 2 comments · Fixed by #94
Closed

NS4000 Unexpected warning in foreach loop #93

appel1 opened this issue Apr 15, 2019 · 2 comments · Fixed by #94
Assignees
Labels
bug Something isn't working
Milestone

Comments

@appel1
Copy link

appel1 commented Apr 15, 2019

NSubstitute 4.0.0.0
NSubstitute.Analyzers.CSharp 1.0.9

Perhaps I'm missing something but this looks like a false positive to me.

using System.Linq;
using NSubstitute;

namespace ClassLibrary3
{
    public class Class1
    {
        public void Foo(IFoo foo, IEnumerable<Description> descriptions)
        {
            foreach (Description d in descriptions)
            {
                foo.Value.Returns(d.Value); // <- Warning	NS4000	Returns() is set with a method that itself calls Returns. This can cause problems with NSubstitute. Consider replacing with a lambda: Returns(x => d.Value).
            }
        }
    }

    public class Description
    {
        public int Value { get; set; }
    }

    public interface IFoo
    {
        int Value { get; }
    }
}
@dtchepak
Copy link
Member

Thanks for raising this! The code looks fine to me. I think you are correct that it is a false positive.

@dtchepak dtchepak added the bug Something isn't working label Apr 15, 2019
@tpodolak tpodolak self-assigned this Apr 15, 2019
tpodolak added a commit that referenced this issue Apr 15, 2019
…ng-in-foreach-loop

[GH-93] - excluding root symbol from reentrant analysys
@tpodolak tpodolak added this to the 1.0.10 milestone Apr 15, 2019
@tpodolak
Copy link
Member

tpodolak commented Jun 4, 2019

Published in 1.0.10

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

Successfully merging a pull request may close this issue.

3 participants