From 139c286098fe7d2b1eaab8db27f0255c573294ad Mon Sep 17 00:00:00 2001 From: Dennis Doomen Date: Fri, 31 Mar 2023 15:45:38 +0200 Subject: [PATCH] Some minor internal naming changes that I found while using the code in a workshop --- .../Equivalency/EquivalencyValidationContext.cs | 4 ++-- .../Equivalency/EquivalencyValidator.cs | 15 +++++++-------- .../Execution/CyclicReferenceDetector.cs | 2 +- .../Equivalency/Execution/ObjectReference.cs | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Src/FluentAssertions/Equivalency/EquivalencyValidationContext.cs b/Src/FluentAssertions/Equivalency/EquivalencyValidationContext.cs index 9cc7fa28f7..5ebbe576b1 100644 --- a/Src/FluentAssertions/Equivalency/EquivalencyValidationContext.cs +++ b/Src/FluentAssertions/Equivalency/EquivalencyValidationContext.cs @@ -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); } diff --git a/Src/FluentAssertions/Equivalency/EquivalencyValidator.cs b/Src/FluentAssertions/Equivalency/EquivalencyValidator.cs index 57ee7958bd..332c2a185f 100644 --- a/Src/FluentAssertions/Equivalency/EquivalencyValidator.cs +++ b/Src/FluentAssertions/Equivalency/EquivalencyValidator.cs @@ -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(() => 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); @@ -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)); diff --git a/Src/FluentAssertions/Equivalency/Execution/CyclicReferenceDetector.cs b/Src/FluentAssertions/Equivalency/Execution/CyclicReferenceDetector.cs index 736ba716bd..626e0367c5 100644 --- a/Src/FluentAssertions/Equivalency/Execution/CyclicReferenceDetector.cs +++ b/Src/FluentAssertions/Equivalency/Execution/CyclicReferenceDetector.cs @@ -26,7 +26,7 @@ public bool IsCyclicReference(ObjectReference reference, CyclicReferenceHandling { bool isCyclic = false; - if (reference.IsComplexType) + if (reference.CompareByMembers) { isCyclic = !observedReferences.Add(reference); diff --git a/Src/FluentAssertions/Equivalency/Execution/ObjectReference.cs b/Src/FluentAssertions/Equivalency/Execution/ObjectReference.cs index 0e5b9925cf..b2f92fc3b1 100644 --- a/Src/FluentAssertions/Equivalency/Execution/ObjectReference.cs +++ b/Src/FluentAssertions/Equivalency/Execution/ObjectReference.cs @@ -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; } /// @@ -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); }