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.

Should().ContainInOrder() - false negative?

See original GitHub issue

Version: 5.3.0

Exception / failure message:

Xunit.Sdk.XunitException: Expected collection {(KnownRoleTypes, System.Collections.Generic.List`1[System.Type]), (HostResultRun, ), (test1, ), (test2, ), (test3, )} to contain items {(test1, ), (test2, ), (test3, )} in order, but (test1, ) (index 0) did not appear (in the right order).
   at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\XUnit2TestFramework.cs:line 32
   at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 225
   at FluentAssertions.Collections.CollectionAssertions`2.ContainInOrder(IEnumerable expected, String because, Object[] becauseArgs) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Collections\CollectionAssertions.cs:line 631

Code:

results.Events.Should().ContainInOrder(
    new Tuple<string, object>("test1", null),
    new Tuple<string, object>("test2", null),
    new Tuple<string, object>("test3", null)
);

The exception seems to contradict itself - the collection does have those items?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
luiscanterocommented, Oct 20, 2021

I ran into a similar problem and found this issue. To repro in 6.1.0 do this:

var results = new List<object>
{
    new Tuple<object, object>("test1", null),
    new Tuple<object, object>("test2", null),
    new Tuple<object, object>("test3", null),
};

results.Should().ContainInOrder(
    new Tuple<string, object>("test1", null),
    new Tuple<string, object>("test2", null),
    new Tuple<string, object>("test3", null)
);

The error is:

FluentAssertions.Execution.AssertionFailedException: 'Expected results {(test1, ), (test2, ), (test3, )} to contain items {(test1, ), (test2, ), (test3, )} in order, but (test1, ) (index 0) did not appear (in the right order).'
1reaction
jnyrupcommented, May 11, 2018

Please provide a complete example. It makes it harder to debug, when one has to guess the type and content of result.events.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tips - Fluent Assertions
Should().Contain(expected);. Expected True, but found False.
Read more >
9 Fluent Assertions Tricks to Save Hours of Your Testing ...
Should().BeTrue(); }. The output message in this case is: Expected saveOperationResult to be true, but found False. Again, much clearer, right?
Read more >
FluentAssertion, check constraint just for condition
You can choose to have a separate test for the positive (true) and negative (false) scenario. From a unit testing best practices document ......
Read more >
Using matchers
String s and Array s as collections; Be as an equality comparison; Being negative; Checking that a snippet of code does not compile;...
Read more >
FluentAssertions.Web
Asserts that a Bad Request HTTP response content contains an error message identifiable by an wildcard error text. Fine grained status assertions. Should()....
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