I'm implementing sortable columns on my Kendo grid and the user-expected behaviour is to allow multiple columns to be sorted at the same time.
Naturally, I'm starting off by writing a unit test to be able to verify that the sorting is (by default) first by Ref
ascending, then Name
ascending.
Test suppliers in question are here:
_context.Suppliers.Add(new Supplier { Ref = "abc", Name = "steve"});
_context.Suppliers.Add(new Supplier { Ref = "abc", Name = "bob"});
_context.Suppliers.Add(new Supplier { Ref = "cde", Name = "ian"});
_context.Suppliers.Add(new Supplier { Ref = "fgh", Name = "dan"});
Then I go and ask the test for my sorted suppliers.
Fluent assertions I know has the BeInAscendingOrder
and BeInDescendingOrder
methods, however even after looking through the documentation and following possibly related questions I couldn't see an example of chaining sorting methods.
My current test verification is like this:
results.Should().HaveCount(4).And.BeInAscendingOrder(x => x.Ref)
.And.BeInAscendingOrder(x => x.Name);
I was expecting the verification to work a bit like LINQ
where it has OrderBy(x => x.Ref).ThenBy(x => x.Name)
.
However when running the test, it is failing because it is expecting the collection to be ordered ascending by Name
(the final sort assertion).
Is there a way to tell Fluent Assertions that the sorts should be applied in conjunction with one another and not just in sequence?
ThenInAscendingOrder
so you might have to resort tosource.OrderBy(x => x.Ref).ThenBy(x => x.Name).ShouldBeEquivalentTo(results, options => options.WithStrictOrdering());
or something more verbose which checks the order explicitly. – ViridianWithStrictOrdering
option that check that actual collection equivalent to and ordered as expected. – Disallow