8000 Pass down the reason to inner `AssertionScope` by IT-VBFK · Pull Request #2318 · fluentassertions/fluentassertions · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Src/FluentAssertions/Execution/AssertionScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ private AssertionScope(IAssertionStrategy assertionStrategy, AssertionScope pare
{
contextData.Add(parent.contextData);
Context = parent.Context;
reason = parent.reason;
callerIdentityProvider = parent.callerIdentityProvider;
}
}
Expand Down Expand Up @@ -147,10 +148,7 @@ public AssertionScope UsingLineBreaks
/// </summary>
public FormattingOptions FormattingOptions { get; } = AssertionOptions.FormattingOptions.Clone();

internal bool Succeeded
{
get => succeeded == true;
}
internal bool Succeeded => succeeded == true;

/// <summary>
/// Adds an explanation of why the assertion is supposed to succeed to the scope.
Expand Down
18 changes: 18 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/DictionarySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,4 +1170,22 @@ public void When_a_custom_rule_is_applied_on_a_dictionary_it_should_apply_it_on_
.WhenTypeIs<double>()
);
}

[Fact]
public void Passing_the_reason_to_the_inner_equivalency_assertion_works()
{
var subject = new Dictionary<string, object>
{
["a"] = new List<int>()
};

var expected = new Dictionary<string, object>
{
["a"] = new List<int> { 42 }
};

Action act = () => subject.Should().BeEquivalentTo(expected, "FOO {0}", "BAR");

act.Should().Throw<XunitException>().WithMessage("*FOO BAR*");
}
}
1 change: 1 addition & 0 deletions docs/_pages/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
0