question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
MarcoRossignolicommented, Jul 11, 2020

I can repro with @petli repro https://github.com/coverlet-coverage/coverlet/issues/760#issuecomment-644265756 At the moment don’t know it’s the same issue of other.

0reactions
MarcoRossignolicommented, Jul 20, 2020

Glad to hear that, thanks for the test!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coverlet doesn't track coverage of method with a LINQ ...
It seems to be the combination of IEnumerable<> and the async state engine that causes coverlet to ignore all lines except the if/foreach...
Read more >
LINQ `Any` not covered by unit test
1 Answer. I suspect the issue is that you are not testing all possible execution paths for the Any . You may need...
Read more >
Measuring .NET Core Test Coverage with Coverlet
I love working with .NET Core on the command line (CLI) and Visual Studio Code. Until recently getting code coverage metrics for your...
Read more >
Complex Query Operators - EF Core
Language Integrated Query (LINQ) contains many complex operators, which combine multiple data sources or does complex processing.
Read more >
What's New in NDepend
Support for Properties and Events. The NDepend code model is now filled with properties and events thanks to the new interfaces IProperty and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found