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 false positive when using an initializer #124

Closed
darrenbiel opened this issue Oct 11, 2019 · 1 comment
Closed

NS4000 false positive when using an initializer #124

darrenbiel opened this issue Oct 11, 2019 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@darrenbiel
Copy link

This seems similar to issue #47 but I am still seeing this in 1.0.10.

When using an initializer in a returns, I get an analysis error NS4000 even if there is no nested returns.

public class TestClass
{
    [Fact]
    public void NS4000_FalsePositive()
    {
        IBook book = SetupBook();
        var bookFinder = Substitute.For<IBookFinder>();

        bookFinder.FavoriteBook.Returns(book); // Doesn't shows analysis error
        bookFinder.Books.Returns(new List<IBook>() { book }); // Shows analysis error
        bookFinder.BookPromoter.Returns(new BookPromoter() { PromotedBook = book }); // Shows analysis error

        Assert.Contains(book, bookFinder.Books);
    }

    private static IBook SetupBook()
    {
        var model = Substitute.For<IBook>();
        model.IsFiction.Returns(true);
        return model;
    }
}

public interface IBook
{
    bool IsFiction { get; set; }
}

public interface IBookFinder
{
    ICollection<IBook> Books { get; }
    IBook FavoriteBook { get; }
    IBookPromoter BookPromoter { get; }
}

public interface IBookPromoter
{
    IBook PromotedBook { get; set; }
}

public class BookPromoter : IBookPromoter
{
    public IBook PromotedBook { get; set; }
}
@tpodolak tpodolak added the bug Something isn't working label Oct 11, 2019
@tpodolak tpodolak added this to the 1.0.11 milestone Oct 11, 2019
@tpodolak
Copy link
Member

Thanks for reporting, your issue has the same root-cause as #106 which was fixed by #107. Fix will be available in next version

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