Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some internal naming improvements #2164

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public IEquivalencyValidationContext Clone()

public bool IsCyclicReference(object expectation)
{
bool isComplexType = expectation is not null && Options.GetEqualityStrategy(expectation.GetType())
bool compareByMembers = expectation is not null && Options.GetEqualityStrategy(expectation.GetType())
is EqualityStrategy.Members or EqualityStrategy.ForceMembers;

var reference = new ObjectReference(expectation, CurrentNode.PathAndName, isComplexType);
var reference = new ObjectReference(expectation, CurrentNode.PathAndName, compareByMembers);
return CyclicReferenceDetector.IsCyclicReference(reference, Options.CyclicReferenceHandling, Reason);
}

Expand Down
15 changes: 7 additions & 8 deletions Src/FluentAssertions/Equivalency/EquivalencyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,38 @@ public void RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidat
{
var scope = AssertionScope.Current;

if (ShouldCompareNodesThisDeep(context.CurrentNode, context.Options, scope))
if (ShouldContinueThisDeep(context.CurrentNode, context.Options, scope))
{
UpdateScopeWithReportableContext(scope, comparands, context.CurrentNode);
TrackWhatIsNeededToProvideContextToFailures(scope, comparands, context.CurrentNode);

if (!context.IsCyclicReference(comparands.Expectation))
{
RunStepsUntilEquivalencyIsProven(comparands, context);
TryToProveNodesAreEquivalent(comparands, context);
}
}
}

private static bool ShouldCompareNodesThisDeep(INode currentNode, IEquivalencyAssertionOptions options,
private static bool ShouldContinueThisDeep(INode currentNode, IEquivalencyAssertionOptions options,
AssertionScope assertionScope)
{
bool shouldRecurse = options.AllowInfiniteRecursion || currentNode.Depth <= MaxDepth;

if (!shouldRecurse)
{
// This will throw, unless we're inside an AssertionScope
assertionScope.FailWith($"The maximum recursion depth of {MaxDepth} was reached. ");
}

return shouldRecurse;
}

private static void UpdateScopeWithReportableContext(AssertionScope scope, Comparands comparands, INode currentNode)
private static void TrackWhatIsNeededToProvideContextToFailures(AssertionScope scope, Comparands comparands, INode currentNode)
{
scope.Context = new Lazy<string>(() => currentNode.Description);

scope.TrackComparands(comparands.Subject, comparands.Expectation);
}

private void RunStepsUntilEquivalencyIsProven(Comparands comparands, IEquivalencyValidationContext context)
private void TryToProveNodesAreEquivalent(Comparands comparands, IEquivalencyValidationContext context)
{
using var _ = context.Tracer.WriteBlock(node => node.Description);

Expand All @@ -71,7 +71,6 @@ private void RunStepsUntilEquivalencyIsProven(Comparands comparands, IEquivalenc
foreach (IEquivalencyStep step in AssertionOptions.EquivalencyPlan)
{
var result = step.Handle(comparands, context, this);

if (result == EquivalencyResult.AssertionCompleted)
{
context.Tracer.WriteLine(getMessage(step));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public bool IsCyclicReference(ObjectReference reference, CyclicReferenceHandling
{
bool isCyclic = false;

if (reference.IsComplexType)
if (reference.CompareByMembers)
{
isCyclic = !observedReferences.Add(reference);

Expand Down
8 changes: 4 additions & 4 deletions Src/FluentAssertions/Equivalency/Execution/ObjectReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ internal class ObjectReference
{
private readonly object @object;
private readonly string path;
private readonly bool? isComplexType;
private readonly bool? compareByMembers;
private string[] pathElements;

public ObjectReference(object @object, string path, bool? isComplexType = null)
public ObjectReference(object @object, string path, bool? compareByMembers = null)
{
this.@object = @object;
this.path = path;
this.isComplexType = isComplexType;
this.compareByMembers = compareByMembers;
}

/// <summary>
Expand Down Expand Up @@ -69,5 +69,5 @@ public override string ToString()
return Invariant($"{{\"{path}\", {@object}}}");
}

public bool IsComplexType => isComplexType ?? (@object?.GetType().OverridesEquals() == false);
public bool CompareByMembers => compareByMembers ?? (@object?.GetType().OverridesEquals() == false);
}