-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Description
Description
SelfReferencingCollectionAssertions.OnlyContain fails when asserting that an empty collection should contain only items matching a predicate, even though the asserted statement is vacuously true.
Complete minimal example reproducing the issue
// Arrange
var actual = new int[0];
// Assert
actual.All(item => true).Should().BeTrue();
actual.Should().OnlyContain(item => true);Expected behavior:
Both assertions to pass.
Actual behavior:
The first assertion passes, but the second fails with message
Expected actual to contain only items matching True, but the collection is empty.
Versions
- Fluent Assertions: 5.10.3
- .NET runtime: .NET Core 3.1
Comments
This issue is similar in nature to my previous issue (whose resolution I'm grateful for). I would think that the behavior of OnlyContain is also by design but that it might be more intuitive for the assertion to always pass on empty collections.
The perhaps counterintuitive behavior of OnlyContain on an empty collection has been mentioned before (although only in passing).
will-molloy
Metadata
Metadata
Assignees
Labels
No labels