-
Notifications
You must be signed in to change notification settings - Fork 731
Description
Discussed in #2143
Originally posted by ArneMancofi March 8, 2023
Description
new object[0].Should().AllSatisfy(o => { }); fails with
Expected collection to contain only items satisfying the inspector, but collection is empty.
This does not implement the documented effect of AllSatisfy:
Asserts that a collection contains only items which meet the criteria provided by the inspector
In particular, any empty collection should always pass this test.
The bug is probably due to two code lines in
fluentassertions/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Lines 2929 to 2930 in c3b9a70
| .ForCondition(subject => subject.Any()) | |
| .FailWith("but collection is empty.") |
Reproduction Steps
// Arrange
var emptyArray = new object[0];
// Act
// Assert
emptyArray.Should().AllSatisfy(o => { });Expected behavior
The test should pass without throwing an exception.
Actual behavior
The test fails with exception
Expected collection to contain only items satisfying the inspector, but collection is empty.
Regression?
This has probably always been this way.
Known Workarounds
Code like this would be a workaround:
if (collection.Any()) collection.Should().AllSatisfy(...);However, reading the documentation of .AllSatisfy(), it should not be necessary.
Configuration
FluentAssertions 6.9.0
.NET 6.0
Other information
The WikiPedia article on universal quantification states that
By convention, the formula ∀x∈∅ P(x) is always true, regardless of the formula P(x)
so it is the documentated behaviour of .AllSatisfy() that is conventionally correct, and the implementation that is not.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status