question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 https://github.com/fluentassertions/fluentassertions/issues/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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisdoomencommented, Nov 15, 2018

Example 2 should be the same as WithoutStrictOrdering. So the order is important.

0reactions
BrunoJuchlicommented, Dec 5, 2018

Taken care of by #974

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releases - Fluent Assertions
FixesPermalink. Provide opt-out to AssertionOptions(o => o.WithStrictOrdering()) -#974; Add collection assertion ContainEquivalentOf ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found