Ensured the maximum depth is properly respecting the "official" definition of depth by dennisdoomen · Pull Request #2145 · fluentassertions/fluentassertions · GitHub
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
3 changes: 2 additions & 1 deletion FluentAssertions.sln.DotSettings
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Equivalency/EquivalencyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public void RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidat
private static bool ShouldCompareNodesThisDeep(INode currentNode, IEquivalencyAssertionOptions options,
AssertionScope assertionScope)
{
bool shouldRecurse = options.AllowInfiniteRecursion || currentNode.Depth < MaxDepth;
bool shouldRecurse = options.AllowInfiniteRecursion || currentNode.Depth <= MaxDepth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line to release notes about this?


if (!shouldRecurse)
{
assertionScope.FailWith("The maximum recursion depth was reached. ");
assertionScope.FailWith($"The maximum recursion depth of {MaxDepth} was reached. ");
}

return shouldRecurse;
Expand Down
4 changes: 4 additions & 0 deletions Src/FluentAssertions/Equivalency/INode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public interface INode
/// <summary>
/// Gets a zero-based number representing the depth within the object graph
/// </summary>
/// <remarks>
/// The root object has a depth of <c>0</c>, the next nested object a depth of <c>1</c>, etc.
/// See also <a href="https://www.geeksforgeeks.org/height-and-depth-of-a-node-in-a-binary-tree/">this article</a>
/// </remarks>
int Depth { get; }

/// <summary>
Expand Down
30 changes: 30 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/BasicSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@ namespace FluentAssertions.Equivalency.Specs;

public class BasicSpecs
{
[Fact]
public void A_null_configuration_is_invalid()
{
// Arrange
var actual = new { };
var expectation = new { };

// Act
Action act = () => actual.Should().BeEquivalentTo(expectation, config: null);

// Assert
act.Should().ThrowExactly<ArgumentNullException>()
.WithParameterName("config");
}

[Fact]
public void A_null_as_the_configuration_is_not_valid_for_inequivalency_assertions()
{
// Arrange
var actual = new { };
var expectation = new { };

// Act
Action act = () => actual.Should().NotBeEquivalentTo(expectation, config: null);

// Assert
act.Should().ThrowExactly<ArgumentNullException>()
.WithParameterName("config");
}

[Fact]
public void When_expectation_is_null_it_should_throw()
{
Expand Down
195 changes: 71 additions & 124 deletions Tests/FluentAssertions.Equivalency.Specs/CyclicReferencesSpecs.cs
Loading