From 8e141222e0d34ea373afa96bff3bafe31f29395b Mon Sep 17 00:00:00 2001 From: bsedighi94 Date: Fri, 25 Nov 2022 08:31:32 +0100 Subject: [PATCH 1/6] Bug Fix: (1829) Nested AssertionScopes do not print inner scope reportables --- Src/FluentAssertions/Execution/AssertionScope.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Src/FluentAssertions/Execution/AssertionScope.cs b/Src/FluentAssertions/Execution/AssertionScope.cs index 69c5c85a1b..8913c0ee97 100644 --- a/Src/FluentAssertions/Execution/AssertionScope.cs +++ b/Src/FluentAssertions/Execution/AssertionScope.cs @@ -395,6 +395,13 @@ public void Dispose() parent.assertionStrategy.HandleFailure(failureMessage); } + IDictionary reportables = contextData.GetReportable(); + + foreach (KeyValuePair reportable in reportables) + { + parent.AddReportable(reportable.Key, reportable.Value.ToString()); + } + parent.AppendTracing(tracing.ToString()); parent = null; From e9ff0709607035d0ec13f0e797ef22bdf951e3ca Mon Sep 17 00:00:00 2001 From: bsedighi94 Date: Fri, 25 Nov 2022 09:45:26 +0100 Subject: [PATCH 2/6] Bug Fix: (1829) counts check added for reportables --- Src/FluentAssertions/Execution/AssertionScope.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Src/FluentAssertions/Execution/AssertionScope.cs b/Src/FluentAssertions/Execution/AssertionScope.cs index 8913c0ee97..a46d8cad95 100644 --- a/Src/FluentAssertions/Execution/AssertionScope.cs +++ b/Src/FluentAssertions/Execution/AssertionScope.cs @@ -397,9 +397,12 @@ public void Dispose() IDictionary reportables = contextData.GetReportable(); - foreach (KeyValuePair reportable in reportables) + if (reportables.Count > 0) { - parent.AddReportable(reportable.Key, reportable.Value.ToString()); + foreach (KeyValuePair reportable in reportables) + { + parent.AddReportable(reportable.Key, reportable.Value.ToString()); + } } parent.AppendTracing(tracing.ToString()); From a3de8d14967e4324ceebfbd54a2b22876a9ea6b6 Mon Sep 17 00:00:00 2001 From: "uray.oernek" Date: Fri, 25 Nov 2022 10:27:41 +0100 Subject: [PATCH 3/6] Bug Fix: (1829) Added test for assertion scope - inner to outer scope --- .../Execution/AssertionScopeSpecs.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs b/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs index 47a5aec385..13c4900724 100644 --- a/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs +++ b/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs @@ -235,6 +235,24 @@ public void When_using_a_custom_strategy_it_should_include_failure_messages_of_a .WithMessage("*but found false*but found true*"); } + [Fact] + public void When_nested_scope_is_desposed_it_passes_reports_to_parent_scope() + { + // Arrange/Act + using (var outerScope = new AssertionScope()) + { + outerScope.AddReportable("outerReportable", "foo"); + + using (var innerScope = new AssertionScope()) + { + innerScope.AddReportable("innerReportable", "bar"); + } + + // Assert + outerScope.Get("innerReportable").Should().Be("bar"); + } + } + public class CustomAssertionStrategy : IAssertionStrategy { private readonly List failureMessages = new(); From 9ede529b9b8d752af2f12d756d3cb9fae6f264ce Mon Sep 17 00:00:00 2001 From: "uray.oernek" Date: Fri, 25 Nov 2022 10:34:08 +0100 Subject: [PATCH 4/6] Bug Fix: (#1829) Added test for assertion scope - inner to outer scope Fixed typo --- Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs b/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs index 13c4900724..8576323280 100644 --- a/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs +++ b/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs @@ -236,7 +236,7 @@ public void When_using_a_custom_strategy_it_should_include_failure_messages_of_a } [Fact] - public void When_nested_scope_is_desposed_it_passes_reports_to_parent_scope() + public void When_nested_scope_is_disposed_it_passes_reports_to_parent_scope() { // Arrange/Act using (var outerScope = new AssertionScope()) From 03fb50a3feb1cb2094fee03a47fb999dbc5b7ea8 Mon Sep 17 00:00:00 2001 From: bsedighi94 Date: Mon, 28 Nov 2022 10:10:21 +0100 Subject: [PATCH 5/6] Open Issues of #1829 are solved and the bug is fixed --- Src/FluentAssertions/Execution/AssertionScope.cs | 11 +---------- .../CollectionAssertionSpecs.BeEquivalentTo.cs | 5 +++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Src/FluentAssertions/Execution/AssertionScope.cs b/Src/FluentAssertions/Execution/AssertionScope.cs index a46d8cad95..5c84beb23e 100644 --- a/Src/FluentAssertions/Execution/AssertionScope.cs +++ b/Src/FluentAssertions/Execution/AssertionScope.cs @@ -395,16 +395,7 @@ public void Dispose() parent.assertionStrategy.HandleFailure(failureMessage); } - IDictionary reportables = contextData.GetReportable(); - - if (reportables.Count > 0) - { - foreach (KeyValuePair reportable in reportables) - { - parent.AddReportable(reportable.Key, reportable.Value.ToString()); - } - } - + parent.contextData.Add(contextData); parent.AppendTracing(tracing.ToString()); parent = null; diff --git a/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs b/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs index 166c2ef16c..2f4cb231a8 100644 --- a/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs +++ b/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs @@ -300,17 +300,18 @@ public void When_asserting_collections_not_to_be_equivalent_with_options_but_sub { // Arrange int[] actual = null; + int[] expectation = new[] { 1, 2, 3 }; // Act Action act = () => { using var _ = new AssertionScope(); - actual.Should().NotBeEquivalentTo(new[] { 1, 2, 3 }, opt => opt, "we want to test the failure {0}", "message"); + actual.Should().NotBeEquivalentTo(expectation, opt => opt, "we want to test the failure {0}", "message"); }; // Assert act.Should().Throw() - .WithMessage("Expected actual not to be equivalent *failure message*, but found ."); + .WithMessage("Expected actual not to be equivalent *failure message*, but found .*"); } [Fact] From 374e3ac328acb6c8c0786b65cbf7d3cd51d64b15 Mon Sep 17 00:00:00 2001 From: 94sedighi Date: Wed, 14 Dec 2022 08:20:14 +0100 Subject: [PATCH 6/6] Updated release notes --- docs/_pages/releases.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index cf8572970f..ea723ba039 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -17,6 +17,7 @@ sidebar: ### Fixes * Quering properties on classes, e.g. `typeof(MyClass).Properties()`, now also includes static properties - [#2054](https://github.com/fluentassertions/fluentassertions/pull/2054) +* Nested AssertionScopes now print the inner scope reportables - [#2044](https://github.com/fluentassertions/fluentassertions/pull/2044) ## 6.8.0