Skip to content

Coverlet doesn't track coverage of method with a LINQ query in an if statement #760

@Shkeeny

Description

@Shkeeny

When a method has a LINQ query in an if :

 public async Task<IAccessResponse> CreateAsync(DocumentEntity entity)
            {
            var list = new List<DocumentEntity> { new DocumentEntity { id = "1" }, new DocumentEntity { id = "2" } };

            if (list.Count(l => l.id == "1") > 1)
                throw new Exception();

            return new AccessResponse();
            }

We get a result in the code coverage, that looks something like this:
image

But if we extract the query to a variable, it seems to work fine:
image

Seems like the issue is reproducible in coverlet.msbuild versions 2.7.0 and 2.8.0.
Version 2.6.3 works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtenet-coverageIssue related to possible incorrect coverage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions