diff --git a/Src/FluentAssertions/Execution/AssertionScope.cs b/Src/FluentAssertions/Execution/AssertionScope.cs index 1114ab2712..f9436ff254 100644 --- a/Src/FluentAssertions/Execution/AssertionScope.cs +++ b/Src/FluentAssertions/Execution/AssertionScope.cs @@ -107,6 +107,7 @@ private AssertionScope(IAssertionStrategy assertionStrategy, AssertionScope pare { contextData.Add(parent.contextData); Context = parent.Context; + reason = parent.reason; callerIdentityProvider = parent.callerIdentityProvider; } } @@ -147,10 +148,7 @@ public AssertionScope UsingLineBreaks /// public FormattingOptions FormattingOptions { get; } = AssertionOptions.FormattingOptions.Clone(); - internal bool Succeeded - { - get => succeeded == true; - } + internal bool Succeeded => succeeded == true; /// /// Adds an explanation of why the assertion is supposed to succeed to the scope. diff --git a/Tests/FluentAssertions.Equivalency.Specs/DictionarySpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/DictionarySpecs.cs index 94f8455d43..ac46be1931 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/DictionarySpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/DictionarySpecs.cs @@ -1170,4 +1170,22 @@ public void When_a_custom_rule_is_applied_on_a_dictionary_it_should_apply_it_on_ .WhenTypeIs() ); } + + [Fact] + public void Passing_the_reason_to_the_inner_equivalency_assertion_works() + { + var subject = new Dictionary + { + ["a"] = new List() + }; + + var expected = new Dictionary + { + ["a"] = new List { 42 } + }; + + Action act = () => subject.Should().BeEquivalentTo(expected, "FOO {0}", "BAR"); + + act.Should().Throw().WithMessage("*FOO BAR*"); + } } diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index d13465d496..6ea43f83f0 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -17,6 +17,7 @@ sidebar: * Fixed formatting error when checking nullable `DateTimeOffset` with `BeWithin(...).Before(...)` - [#2312](https://github.com/fluentassertions/fluentassertions/pull/2312) * `BeEquivalentTo` will now find and can map subject properties that are implemented through an explicitly-implemented interface - [#2152](https://github.com/fluentassertions/fluentassertions/pull/2152) +* Fixed that the `because` and `becauseArgs` were not passed down the equivalency tree - [#2318](https://github.com/fluentassertions/fluentassertions/pull/2318) ### Breaking Changes (for users) * Moved support for `DataSet`, `DataTable`, `DataRow` and `DataColumn` into a new package `FluentAssertions.DataSet` - [#2267](https://github.com/fluentassertions/fluentassertions/pull/2267)