Create a version of `SatisfyRespectively` that ignores order
See original GitHub issueDescription
The SatisfyRespectively
method is a great way to validate fixed elements in a collection, and I’ve been using it extensively since it was recently introduced.
However, I’ve come across a few cases where I want to perform the checks on all elements on a sequence, but I don’t care about the order that they are returned (as long as they match the exact amount of assertions and only once each).
I’d like to propose the creation of a variation of SatisfyRespectively
that ignores the order where the assertions are found in the collection, but otherwise work similarly.
Example
// Arrange
var numbers = new [] { 1, 2 };
// Assert
numbers.Should().SatisfyDistinctly(
n => n.Should().Be(2),
n => n.Should().Be(1));
I used the name SatisfyDistinctly
here as Distinctly
was the first logical antonym of Respectively
that I found, but any fitting name would suffice.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:10 (5 by maintainers)
Top Results From Across the Web
FluentAssertions: equivalence of sorted lists
By default, ShouldBeEquivalentTo() will ignore the order in the collections because in most cases two collections are equivalent if they ...
Read more >ShouldBeEquivalentTo() forces array strict ordering. ...
If I have an array property, the order of its values needs to be the same when asserting with Should().BeEquivalentTo(). I'm arguing that...
Read more >Releases - Fluent Assertions
Added ContainInConsecutiveOrder and NotContainInConsecutiveOrder assertions to check if a collection contains items in a specific order and to be ...
Read more >Collections
Asserting that a collection contains items in a certain order is as easy as using one of the several overloads of BeInAscendingOrder or...
Read more >EE120 - Fall'15 - Lecture 1 Notes1
implementation with fewer memory registers, recall that changing the order of two LTI systems in series does not change the result:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know what it means, but only after looking it up 😉 I just believe it would have been a lot easier for non-native English speakers to understand if it was named
SatisfyInOrder
instead ofSatisfyRespectively
. That would also fit with the already existingContainInOrder
, which is not calledContainRespectively
. To my knowledge, there are no other instances in the library, whereRespectively
is used, which also makes it a bit unnatural to look for. I actually don’t even recall ever encountering a method containing that word 😃The documentation doesn’t even say it’s evaluated in order either (as I understand it):
So maybe a simple improvement would include that the element inspectors will be matched against the exact order of the collection?
To me, there is a big difference about being correct in the dictionary definition compared to a more common used term already used in the library and in the entire framework 😃
This is a great point IMHO. Having methods that behave similarly in the API but are named differently is bad for consistency/discoverability.
The rename to
SatisfyInOrder
does make quite a bit of sense to me as well, even if I myself knew what the “Respectively” meant originally.