nunit / nunit.analyzers

Roslyn analyzers for writing unit tests with NUnit
MIT License
86 stars 29 forks source link

[suggestion] NUnit2014 doesn't flag Enumerable.Any(predicate) #749

Open Bartleby2718 opened 1 month ago

Bartleby2718 commented 1 month ago

Very similar to #748, but for .Any(). NUnit.Analyzers should be able to convert

Assert.That(numbers.Any<int>(x => x % 2 == 0));

to

Assert.That(numbers, Has.Some.Matches<int>(x => x % 2 == 0));

but it doesn't.

manfred-brands commented 1 month ago

To call never asked for functionality a bug is a bit steep isn't it.

Bartleby2718 commented 1 month ago

Well, the description for NUnit2014 is "Use SomeItemsConstraint for better assertion messages in case of failure" as opposed to "Use ContainConstraint for better assertion messages in case of failure." 🤷

I can change the wording if you believe this should not be part of NUnit2014 .

manfred-brands commented 1 month ago

If you are going to quote documentation, then be complete:

Using `Does.Contain` (or `Does.Not.Contain`) constraint will lead to better assertion messages in case of failure,
so this analyzer marks all usages of string `Contains` method where it is possible to replace
with `Does.Contain` constraint.

Nothing in here about Any or Matches