Skip to content

Provide opt-out to AssertionOptions(o => o.WithStrictOrdering()) #966

@BrunoJuchli

Description

@BrunoJuchli

Breaking change in 5.5 (coming from 5.4.2)

We globally set the default assertion equivalency options using:

AssertionOptions.AssertEquivalencyUsing(options => options
	.WithStrictOrdering());

Because we believe it's safer to require strict ordering by default (I can provide a reasoning if anyone is interested).

Now, in special cases where the order did not matter, we used:

collection.Should().BeEquivalentTo(
    ...,
    options => options.WithoutStrictOrderingFor(info => true));

to counteract the effect of WithStrictOrdering(). For certain scenarios this has stopped working with 5.5.0 (we now have a test fail which didn't fail before).

Proposal

WithoutStrictOrderingFor(info => true)) was a bit of an ugly workaround in the first place.
Instead of "reverting" FluentAssertions to work as before it seems more sensible to actually support WithoutStrictOrdering as a proper counterpart to WithStrictOrdering.

SelfReferenceEquivalencyAssertionOptions<TSelf>.WithStrictOrdering()

performs

orderingRules.Add(new MatchAllOrderingRule());

The suggested SelfReferenceEquivalencyAssertionOptions<TSelf>.WithoutStrictOrdering() should perform something along the lines of:

var strictOrderingRules = orderingRules.OfType<MatchAllOrderingRule>().ToList();
foreach(var strictOrderingRule in strictOrderingRules)
{
    orderingRules.Remove(strictOrderingRule)
}

Complete minimal example reproducing the issue

I have taken the liberty of not providing a repro - for now. If necessary I can produce one, but since I don't really consider the 5.5 behavior a bug It seems more appropriate to focus on the feature request - which, I believe, does resolve the issue appropriately.

Note: I suspect this to be connected to #965
the reason is that this problem only surfaces in a very few tests even though we apply WithoutStrictOrderingFor(info => true) 166 times.

Please also note that I have tested the following cases:

Default WithStrictOrdering, override with WithoutStrictOrderingFor(info => true)

--> used to work in 5.4.2
--> doesn't work in 5.5 (i.E. breaking change)

Default WithStrictOrdering, no WithoutStrictOrderingFor, expected and actual sequence match

--> works in 5.5 (expected)

Default without strict ordering, no WithoutStrictOrderingFor

--> works in 5.5 (expected)

Versions

  • 5.5 (before: 5.4.2)
  • .Net Framework 4.7.2

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions