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.

Nested AssertionScopes do not print inner scope reportables

See original GitHub issue

Description

Nested AssertionScopes only report the outer-most scope reportables on failure. This is true regardless of whether the outer scope has any reportables – i.e., if only the inner scope has reportables, nothing is reported.

Complete minimal example reproducing the issue

[TestMethod]
public void TestNestedAssertionScopes()
{
    using (var outerScope = new AssertionScope())
    {
        outerScope.AddReportable("outerReportable", "foo"); // no behavior change if this is omitted
        // in my real use case, the inner scope is in a for loop with changing innerScope reportable values, so I can't use a single scope; 
        // the outer scope is used to ensure that a failure of one loop item continues running the rest of the loop
        using (var innerScope = new AssertionScope()) 
        {
            innerScope.AddReportable("innerReportable", "bar");

            int testVal = 2;
            testVal.Should().Be(1);
        }
    }
}

Expected behavior:

Message: Expected testVal to be 1, but found 2.

With outerReportable:
foo
With innerReportable:
bar

Actual behavior:

Message: Expected testVal to be 1, but found 2.

With outerReportable:
foo

Versions

  • Which version of Fluent Assertions are you using? 6.5.1
  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1. .NET Framework 4.7.2

Additional Information

using Microsoft.VisualStudio.TestTools.UnitTesting test framework

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
94sedighicommented, Nov 24, 2022

Me and my friend Ruijin92 are two new Contributors working together on Issues and having our first experience in an open source project. We already have a solution for this bug and would be happy if you assign this “good first issue” to me or Ruijin92.

1reaction
dennisdoomencommented, Jul 20, 2022

I think the most straightforward approach would be to have the inner scope yield its reportables to the “parent” when disposed, as is done with failure messages. There is a potential conflict here if inner and outer scopes attempt to use the same key though, as well as a few other cases - only the final value for a given key would be reported. I’m note entirely sure what the most appropriate behaviour should be.

I think that’s an acceptable solution. We just need to make sure that Discard also discard the reportables.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releases - Fluent Assertions
Properties() , now also includes static properties - #2054; Nested AssertionScopes now print the inner scope reportables - #2044; Throw ArgumentException ...
Read more >
Using Assertion Scopes to execute multiple Assertions in ...
Using Assertion Scopes, we can batch multiple assertions into a AssertionScope so that FluentAssertions will only throw the one exception at ...
Read more >
about nested transaction, the outer scope gives me ...
I have nested transactions. The outer method calls an inner method SaveChangesToSource that opens another transaction scope. Actually I know my ...
Read more >
Coding Rules
An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers (§8.7)...
Read more >
American Carbon Registry® Nested REDD+ Standard
5 Defined scope of REDD+ activities: The jurisdictional framework shall include the project activity type to be registered on ACR as an eligible...
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