Add ability to dynamically limit graph depth in `Formatter` · Issue #1274 · fluentassertions/fluentassertions · GitHub
Skip to content

Add ability to dynamically limit graph depth in Formatter #1274

Description

@cd21h

Add ability to limit graph depth in Formatter

Currently it is hardcoded to 5, which makes error messages for assertions on collections containing complex object graphs unreadable.

 private static string FormatChild(string path, object childValue, bool useLineBreaks, ObjectGraph graph) {
    /// ...
                else if (graph.Depth > 5)
                {
                    return "{Maximum recursion depth was reached…}";
                }
}

Would be nice to have an option to pass depth to collection assertion e.g.

result.Should().Contain(p => p.Foo == "Bar", maxDepth: 1);

Current behavior

For list of 2 complex objects, I'm getting message Expected result { ... containing almost 200 lines of text

Versions

  • FluentAssertions: 5.10.2
  • .NET Core 2.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions