diff --git a/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs b/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs index 3c33ae9a28..4ad2496892 100644 --- a/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs +++ b/Src/FluentAssertions/Collections/GenericCollectionAssertions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -377,7 +377,7 @@ public AndConstraint BeEquivalentTo(IEnumerable), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); return new AndConstraint((TAssertions)this); } @@ -913,7 +913,7 @@ public AndWhichConstraint ContainEquivalentOf(TExp CompileTimeType = typeof(TExpectation), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); string[] failures = scope.Discard(); @@ -2416,7 +2416,7 @@ public AndConstraint NotContainEquivalentOf(TExpectat CompileTimeType = typeof(TExpectation), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); string[] failures = scope.Discard(); diff --git a/Src/FluentAssertions/Collections/GenericDictionaryAssertions.cs b/Src/FluentAssertions/Collections/GenericDictionaryAssertions.cs index 765a90f2ad..ee412e1d81 100644 --- a/Src/FluentAssertions/Collections/GenericDictionaryAssertions.cs +++ b/Src/FluentAssertions/Collections/GenericDictionaryAssertions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -233,7 +233,7 @@ public AndConstraint BeEquivalentTo(TExpectation expe CompileTimeType = typeof(TExpectation), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); return new AndConstraint((TAssertions)this); } diff --git a/Src/FluentAssertions/Collections/StringCollectionAssertions.cs b/Src/FluentAssertions/Collections/StringCollectionAssertions.cs index 82e4498f3c..6344dd8f14 100644 --- a/Src/FluentAssertions/Collections/StringCollectionAssertions.cs +++ b/Src/FluentAssertions/Collections/StringCollectionAssertions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -144,7 +144,7 @@ public AndConstraint BeEquivalentTo(IEnumerable expectation CompileTimeType = typeof(IEnumerable), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); return new AndConstraint((TAssertions)this); } diff --git a/Src/FluentAssertions/Equivalency/EquivalencyResult.cs b/Src/FluentAssertions/Equivalency/EquivalencyResult.cs index 5fb0786888..b8f537e7e1 100644 --- a/Src/FluentAssertions/Equivalency/EquivalencyResult.cs +++ b/Src/FluentAssertions/Equivalency/EquivalencyResult.cs @@ -3,5 +3,5 @@ namespace FluentAssertions.Equivalency; public enum EquivalencyResult { ContinueWithNext, - AssertionCompleted + EquivalencyProven } diff --git a/Src/FluentAssertions/Equivalency/EquivalencyStep.cs b/Src/FluentAssertions/Equivalency/EquivalencyStep.cs index ddbbc2f68e..52d5666eea 100644 --- a/Src/FluentAssertions/Equivalency/EquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/EquivalencyStep.cs @@ -1,4 +1,4 @@ -namespace FluentAssertions.Equivalency; +namespace FluentAssertions.Equivalency; /// /// Convenient implementation of that will only invoke @@ -6,19 +6,19 @@ public abstract class EquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (!typeof(T).IsAssignableFrom(comparands.GetExpectedType(context.Options))) { return EquivalencyResult.ContinueWithNext; } - return OnHandle(comparands, context, nestedValidator); + return OnHandle(comparands, context, valueChildNodes); } /// /// Implements , but only gets called when the expected type matches . /// protected abstract EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator); + IValidateChildNodeEquivalency nested); } diff --git a/Src/FluentAssertions/Equivalency/IEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/IEquivalencyStep.cs index bd55ae1774..d4f744b5ea 100644 --- a/Src/FluentAssertions/Equivalency/IEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/IEquivalencyStep.cs @@ -9,11 +9,11 @@ public interface IEquivalencyStep /// Executes an operation such as an equivalency assertion on the provided . /// /// - /// Should return if the subject matches the expectation or if no additional assertions + /// Should return if the subject matches the expectation or if no additional assertions /// have to be executed. Should return otherwise. /// /// /// May throw when preconditions are not met or if it detects mismatching data. /// - EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator); + EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IValidateChildNodeEquivalency valueChildNodes); } diff --git a/Src/FluentAssertions/Equivalency/IEquivalencyValidator.cs b/Src/FluentAssertions/Equivalency/IValidateChildNodeEquivalency.cs similarity index 56% rename from Src/FluentAssertions/Equivalency/IEquivalencyValidator.cs rename to Src/FluentAssertions/Equivalency/IValidateChildNodeEquivalency.cs index 1d7aacb28e..dfc38ad990 100644 --- a/Src/FluentAssertions/Equivalency/IEquivalencyValidator.cs +++ b/Src/FluentAssertions/Equivalency/IValidateChildNodeEquivalency.cs @@ -1,9 +1,9 @@ namespace FluentAssertions.Equivalency; -public interface IEquivalencyValidator +public interface IValidateChildNodeEquivalency { /// /// Runs a deep recursive equivalency assertion on the provided . /// - void RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context); + void AssertEquivalencyOf(Comparands comparands, IEquivalencyValidationContext context); } diff --git a/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs index 27bb4af3fd..016a566003 100644 --- a/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/MultiDimensionalArrayEquivalencyStep.cs @@ -11,7 +11,7 @@ namespace FluentAssertions.Equivalency; internal class MultiDimensionalArrayEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (comparands.Expectation is not Array expectationAsArray || expectationAsArray.Rank == 1) { @@ -22,7 +22,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon { if (expectationAsArray.Length == 0) { - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } Digit digit = BuildDigitsRepresentingAllIndices(expectationAsArray); @@ -36,12 +36,12 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon IEquivalencyValidationContext itemContext = context.AsCollectionItem(listOfIndices); - nestedValidator.RecursivelyAssertEquality(new Comparands(subject, expectation, typeof(object)), itemContext); + valueChildNodes.AssertEquivalencyOf(new Comparands(subject, expectation, typeof(object)), itemContext); } while (digit.Increment()); } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static Digit BuildDigitsRepresentingAllIndices(Array subjectAsArray) diff --git a/Src/FluentAssertions/Equivalency/Steps/AssertionRuleEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/AssertionRuleEquivalencyStep.cs index 4c3609bccd..ce2116a0fe 100644 --- a/Src/FluentAssertions/Equivalency/Steps/AssertionRuleEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/AssertionRuleEquivalencyStep.cs @@ -23,7 +23,7 @@ public AssertionRuleEquivalencyStep( } public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { bool success = false; @@ -41,7 +41,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon { // Convert into a child context context = context.Clone(); - converter.Handle(comparands, context, nestedValidator); + converter.Handle(comparands, context, valueChildNodes); converted = true; } @@ -59,7 +59,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon } } - return success ? EquivalencyResult.AssertionCompleted : EquivalencyResult.ContinueWithNext; + return success ? EquivalencyResult.EquivalencyProven : EquivalencyResult.ContinueWithNext; } private bool AppliesTo(Comparands comparands, INode currentNode) => predicate(new ObjectInfo(comparands, currentNode)); diff --git a/Src/FluentAssertions/Equivalency/Steps/AutoConversionStep.cs b/Src/FluentAssertions/Equivalency/Steps/AutoConversionStep.cs index 55f9f4db5d..e91c7daf5b 100644 --- a/Src/FluentAssertions/Equivalency/Steps/AutoConversionStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/AutoConversionStep.cs @@ -14,7 +14,7 @@ namespace FluentAssertions.Equivalency.Steps; public class AutoConversionStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (!context.Options.ConversionSelector.RequiresConversion(comparands, context.CurrentNode)) { diff --git a/Src/FluentAssertions/Equivalency/Steps/DictionaryEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/DictionaryEquivalencyStep.cs index e0acf0f406..67dff5dbf2 100644 --- a/Src/FluentAssertions/Equivalency/Steps/DictionaryEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/DictionaryEquivalencyStep.cs @@ -9,7 +9,7 @@ public class DictionaryEquivalencyStep : EquivalencyStep { [SuppressMessage("ReSharper", "PossibleNullReferenceException")] protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency nested) { var subject = comparands.Subject as IDictionary; var expectation = comparands.Expectation as IDictionary; @@ -23,7 +23,7 @@ protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalenc context.Tracer.WriteLine(member => Invariant($"Recursing into dictionary item {key} at {member.Description}")); - nestedValidator.RecursivelyAssertEquality(new Comparands(subject[key], expectation[key], typeof(object)), + nested.AssertEquivalencyOf(new Comparands(subject[key], expectation[key], typeof(object)), context.AsDictionaryItem(key)); } else @@ -37,7 +37,7 @@ protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalenc } } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static bool PreconditionsAreMet(IDictionary expectation, IDictionary subject) diff --git a/Src/FluentAssertions/Equivalency/Steps/EnumEqualityStep.cs b/Src/FluentAssertions/Equivalency/Steps/EnumEqualityStep.cs index 274f6a7c3e..a0251192ca 100644 --- a/Src/FluentAssertions/Equivalency/Steps/EnumEqualityStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/EnumEqualityStep.cs @@ -11,7 +11,7 @@ namespace FluentAssertions.Equivalency.Steps; public class EnumEqualityStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (!comparands.GetExpectedType(context.Options).IsEnum) { @@ -48,7 +48,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon } } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static void HandleByValue(Comparands comparands, Reason reason) diff --git a/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyStep.cs index 996224f5aa..45fc7d57e1 100644 --- a/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyStep.cs @@ -8,7 +8,7 @@ namespace FluentAssertions.Equivalency.Steps; public class EnumerableEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (!IsCollection(comparands.GetExpectedType(context.Options))) { @@ -17,7 +17,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon if (AssertSubjectIsCollection(comparands.Subject)) { - var validator = new EnumerableEquivalencyValidator(nestedValidator, context) + var validator = new EnumerableEquivalencyValidator(valueChildNodes, context) { Recursive = context.CurrentNode.IsRoot || context.Options.IsRecursive, OrderingRules = context.Options.OrderingRules @@ -26,7 +26,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon validator.Execute(ToArray(comparands.Subject), ToArray(comparands.Expectation)); } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static bool AssertSubjectIsCollection(object subject) diff --git a/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyValidator.cs b/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyValidator.cs index f9005628be..71de9e6657 100644 --- a/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyValidator.cs +++ b/Src/FluentAssertions/Equivalency/Steps/EnumerableEquivalencyValidator.cs @@ -16,12 +16,12 @@ internal class EnumerableEquivalencyValidator #region Private Definitions - private readonly IEquivalencyValidator parent; + private readonly IValidateChildNodeEquivalency parent; private readonly IEquivalencyValidationContext context; #endregion - public EnumerableEquivalencyValidator(IEquivalencyValidator parent, IEquivalencyValidationContext context) + public EnumerableEquivalencyValidator(IValidateChildNodeEquivalency parent, IEquivalencyValidationContext context) { this.parent = parent; this.context = context; @@ -195,7 +195,7 @@ private string[] TryToMatch(object subject, T expectation, int expectationInd { using var scope = new AssertionScope(); - parent.RecursivelyAssertEquality(new Comparands(subject, expectation, typeof(T)), + parent.AssertEquivalencyOf(new Comparands(subject, expectation, typeof(T)), context.AsCollectionItem(expectationIndex)); return scope.Discard(); @@ -207,7 +207,7 @@ private bool StrictlyMatchAgainst(object[] subjects, T expectation, int expec object subject = subjects[expectationIndex]; IEquivalencyValidationContext equivalencyValidationContext = context.AsCollectionItem(expectationIndex); - parent.RecursivelyAssertEquality(new Comparands(subject, expectation, typeof(T)), equivalencyValidationContext); + parent.AssertEquivalencyOf(new Comparands(subject, expectation, typeof(T)), equivalencyValidationContext); bool failed = scope.HasFailures(); return !failed; diff --git a/Src/FluentAssertions/Equivalency/Steps/EqualityComparerEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/EqualityComparerEquivalencyStep.cs index 42c9df3677..2ba66b8c9e 100644 --- a/Src/FluentAssertions/Equivalency/Steps/EqualityComparerEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/EqualityComparerEquivalencyStep.cs @@ -14,7 +14,7 @@ public EqualityComparerEquivalencyStep(IEqualityComparer comparer) } public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { var expectedType = context.Options.UseRuntimeTyping ? comparands.RuntimeType : comparands.CompileTimeType; @@ -39,7 +39,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon .FailWith("Expected {context:object} to be equal to {1} according to {0}{because}, but {2} was not.", comparer.ToString(), comparands.Expectation, comparands.Subject); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } public override string ToString() diff --git a/Src/FluentAssertions/Equivalency/Steps/GenericDictionaryEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/GenericDictionaryEquivalencyStep.cs index e642b4b40a..f10a166a19 100644 --- a/Src/FluentAssertions/Equivalency/Steps/GenericDictionaryEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/GenericDictionaryEquivalencyStep.cs @@ -11,13 +11,13 @@ public class GenericDictionaryEquivalencyStep : IEquivalencyStep { #pragma warning disable SA1110 // Allow opening parenthesis on new line to reduce line length private static readonly MethodInfo AssertDictionaryEquivalenceMethod = - new Action, IDictionary> (AssertDictionaryEquivalence).GetMethodInfo().GetGenericMethodDefinition(); #pragma warning restore SA1110 public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (comparands.Expectation is null) { @@ -40,10 +40,10 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon if (IsNotNull(comparands.Subject) && EnsureSubjectIsOfTheExpectedDictionaryType(comparands, expectedDictionary) is { } actualDictionary) { - AssertDictionaryEquivalence(comparands, context, nestedValidator, actualDictionary, expectedDictionary); + AssertDictionaryEquivalence(comparands, context, valueChildNodes, actualDictionary, expectedDictionary); } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static bool IsNonGenericDictionary(object subject) @@ -148,7 +148,7 @@ private static void FailWithLengthDifference( EquivalencyValidationContext context, - IEquivalencyValidator parent, + IValidateChildNodeEquivalency parent, IEquivalencyOptions options, IDictionary subject, IDictionary expectation) @@ -180,7 +180,7 @@ private static void AssertDictionaryEquivalence(key)); } } diff --git a/Src/FluentAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs index a8853b1380..1ff5fb4148 100644 --- a/Src/FluentAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs @@ -16,7 +16,7 @@ public class GenericEnumerableEquivalencyStep : IEquivalencyStep #pragma warning restore SA1110 public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { Type expectedType = comparands.GetExpectedType(context.Options); @@ -35,7 +35,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon if (AssertSubjectIsCollection(comparands.Subject)) { - var validator = new EnumerableEquivalencyValidator(nestedValidator, context) + var validator = new EnumerableEquivalencyValidator(valueChildNodes, context) { Recursive = context.CurrentNode.IsRoot || context.Options.IsRecursive, OrderingRules = context.Options.OrderingRules @@ -56,7 +56,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon } } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static void HandleImpl(EnumerableEquivalencyValidator validator, object[] subject, IEnumerable expectation) => diff --git a/Src/FluentAssertions/Equivalency/Steps/ReferenceEqualityEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/ReferenceEqualityEquivalencyStep.cs index dc1e6b6018..c41e899078 100644 --- a/Src/FluentAssertions/Equivalency/Steps/ReferenceEqualityEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/ReferenceEqualityEquivalencyStep.cs @@ -3,10 +3,10 @@ public class ReferenceEqualityEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { return ReferenceEquals(comparands.Subject, comparands.Expectation) - ? EquivalencyResult.AssertionCompleted + ? EquivalencyResult.EquivalencyProven : EquivalencyResult.ContinueWithNext; } } diff --git a/Src/FluentAssertions/Equivalency/Steps/RunAllUserStepsEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/RunAllUserStepsEquivalencyStep.cs index 6bfc9d801c..114a0aa726 100644 --- a/Src/FluentAssertions/Equivalency/Steps/RunAllUserStepsEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/RunAllUserStepsEquivalencyStep.cs @@ -7,13 +7,13 @@ public class RunAllUserStepsEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { foreach (IEquivalencyStep step in context.Options.UserEquivalencySteps) { - if (step.Handle(comparands, context, nestedValidator) == EquivalencyResult.AssertionCompleted) + if (step.Handle(comparands, context, valueChildNodes) == EquivalencyResult.EquivalencyProven) { - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } diff --git a/Src/FluentAssertions/Equivalency/Steps/SimpleEqualityEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/SimpleEqualityEquivalencyStep.cs index 0d15f6c0ea..0e2b955cf4 100644 --- a/Src/FluentAssertions/Equivalency/Steps/SimpleEqualityEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/SimpleEqualityEquivalencyStep.cs @@ -3,13 +3,13 @@ namespace FluentAssertions.Equivalency.Steps; public class SimpleEqualityEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (!context.Options.IsRecursive && !context.CurrentNode.IsRoot) { comparands.Subject.Should().Be(comparands.Expectation, context.Reason.FormattedMessage, context.Reason.Arguments); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } return EquivalencyResult.ContinueWithNext; diff --git a/Src/FluentAssertions/Equivalency/Steps/StringEqualityEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/StringEqualityEquivalencyStep.cs index 502e42b43e..00a736626c 100644 --- a/Src/FluentAssertions/Equivalency/Steps/StringEqualityEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/StringEqualityEquivalencyStep.cs @@ -6,7 +6,7 @@ namespace FluentAssertions.Equivalency.Steps; public class StringEqualityEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { Type expectationType = comparands.GetExpectedType(context.Options); @@ -17,7 +17,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon if (!ValidateAgainstNulls(comparands, context.CurrentNode)) { - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } bool subjectIsString = ValidateSubjectIsString(comparands, context.CurrentNode); @@ -32,7 +32,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon context.Reason.FormattedMessage, context.Reason.Arguments); } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static Func, EquivalencyOptions> diff --git a/Src/FluentAssertions/Equivalency/Steps/StructuralEqualityEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/StructuralEqualityEquivalencyStep.cs index 2f3eb9abcf..23d022e952 100644 --- a/Src/FluentAssertions/Equivalency/Steps/StructuralEqualityEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/StructuralEqualityEquivalencyStep.cs @@ -8,7 +8,7 @@ namespace FluentAssertions.Equivalency.Steps; public class StructuralEqualityEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (!context.CurrentNode.IsRoot && !context.Options.IsRecursive) { @@ -45,15 +45,15 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon foreach (IMember selectedMember in selectedMembers) { - AssertMemberEquality(comparands, context, nestedValidator, selectedMember, context.Options); + AssertMemberEquality(comparands, context, valueChildNodes, selectedMember, context.Options); } } - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } private static void AssertMemberEquality(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator parent, IMember selectedMember, IEquivalencyOptions options) + IValidateChildNodeEquivalency parent, IMember selectedMember, IEquivalencyOptions options) { IMember matchingMember = FindMatchFor(selectedMember, context.CurrentNode, comparands.Subject, options); @@ -73,7 +73,7 @@ private static void AssertMemberEquality(Comparands comparands, IEquivalencyVali selectedMember.Name = matchingMember.Name; } - parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(selectedMember)); + parent.AssertEquivalencyOf(nestedComparands, context.AsNestedMember(selectedMember)); } } diff --git a/Src/FluentAssertions/Equivalency/Steps/ValueTypeEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/ValueTypeEquivalencyStep.cs index 71a131c275..c9270e421b 100644 --- a/Src/FluentAssertions/Equivalency/Steps/ValueTypeEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/ValueTypeEquivalencyStep.cs @@ -8,7 +8,7 @@ namespace FluentAssertions.Equivalency.Steps; public class ValueTypeEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { Type expectationType = comparands.GetExpectedType(context.Options); EqualityStrategy strategy = context.Options.GetEqualityStrategy(expectationType); @@ -28,7 +28,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon comparands.Subject.Should().Be(comparands.Expectation, context.Reason.FormattedMessage, context.Reason.Arguments); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } return EquivalencyResult.ContinueWithNext; diff --git a/Src/FluentAssertions/Equivalency/Steps/XAttributeEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/XAttributeEquivalencyStep.cs index b9ed03a5b7..1f960da7b9 100644 --- a/Src/FluentAssertions/Equivalency/Steps/XAttributeEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/XAttributeEquivalencyStep.cs @@ -5,13 +5,13 @@ namespace FluentAssertions.Equivalency.Steps; public class XAttributeEquivalencyStep : EquivalencyStep { protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency nested) { var subject = (XAttribute)comparands.Subject; var expectation = (XAttribute)comparands.Expectation; subject.Should().Be(expectation, context.Reason.FormattedMessage, context.Reason.Arguments); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } diff --git a/Src/FluentAssertions/Equivalency/Steps/XDocumentEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/XDocumentEquivalencyStep.cs index 76f569bee3..b7556b4788 100644 --- a/Src/FluentAssertions/Equivalency/Steps/XDocumentEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/XDocumentEquivalencyStep.cs @@ -5,13 +5,13 @@ namespace FluentAssertions.Equivalency.Steps; public class XDocumentEquivalencyStep : EquivalencyStep { protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency nested) { var subject = (XDocument)comparands.Subject; var expectation = (XDocument)comparands.Expectation; subject.Should().BeEquivalentTo(expectation, context.Reason.FormattedMessage, context.Reason.Arguments); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } diff --git a/Src/FluentAssertions/Equivalency/Steps/XElementEquivalencyStep.cs b/Src/FluentAssertions/Equivalency/Steps/XElementEquivalencyStep.cs index 022038ca6c..8e01b45938 100644 --- a/Src/FluentAssertions/Equivalency/Steps/XElementEquivalencyStep.cs +++ b/Src/FluentAssertions/Equivalency/Steps/XElementEquivalencyStep.cs @@ -5,13 +5,13 @@ namespace FluentAssertions.Equivalency.Steps; public class XElementEquivalencyStep : EquivalencyStep { protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency nested) { var subject = (XElement)comparands.Subject; var expectation = (XElement)comparands.Expectation; subject.Should().BeEquivalentTo(expectation, context.Reason.FormattedMessage, context.Reason.Arguments); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } diff --git a/Src/FluentAssertions/Equivalency/EquivalencyValidator.cs b/Src/FluentAssertions/Equivalency/ValidateChildNodeEquivalency.cs similarity index 85% rename from Src/FluentAssertions/Equivalency/EquivalencyValidator.cs rename to Src/FluentAssertions/Equivalency/ValidateChildNodeEquivalency.cs index 928236ed78..0dfa3776e4 100644 --- a/Src/FluentAssertions/Equivalency/EquivalencyValidator.cs +++ b/Src/FluentAssertions/Equivalency/ValidateChildNodeEquivalency.cs @@ -7,7 +7,7 @@ namespace FluentAssertions.Equivalency; /// /// Is responsible for validating the equivalency of a subject with another object. /// -public class EquivalencyValidator : IEquivalencyValidator +public class ValidateChildNodeEquivalency : IValidateChildNodeEquivalency { private const int MaxDepth = 10; @@ -19,7 +19,7 @@ public void AssertEquality(Comparands comparands, EquivalencyValidationContext c scope.AddReportable("configuration", () => context.Options.ToString()); scope.BecauseOf(context.Reason); - RecursivelyAssertEquality(comparands, context); + RecursivelyAssertEquivalencyOf(comparands, context); if (context.TraceWriter is not null) { @@ -27,7 +27,12 @@ public void AssertEquality(Comparands comparands, EquivalencyValidationContext c } } - public void RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context) + private void RecursivelyAssertEquivalencyOf(Comparands comparands, IEquivalencyValidationContext context) + { + AssertEquivalencyOf(comparands, context); + } + + public void AssertEquivalencyOf(Comparands comparands, IEquivalencyValidationContext context) { var scope = AssertionScope.Current; @@ -69,7 +74,7 @@ private void TryToProveNodesAreEquivalent(Comparands comparands, IEquivalencyVal foreach (IEquivalencyStep step in AssertionOptions.EquivalencyPlan) { var result = step.Handle(comparands, context, this); - if (result == EquivalencyResult.AssertionCompleted) + if (result == EquivalencyResult.EquivalencyProven) { context.Tracer.WriteLine(GetMessage(step)); diff --git a/Src/FluentAssertions/Numeric/ComparableTypeAssertions.cs b/Src/FluentAssertions/Numeric/ComparableTypeAssertions.cs index 805812df65..7b4e043b0a 100644 --- a/Src/FluentAssertions/Numeric/ComparableTypeAssertions.cs +++ b/Src/FluentAssertions/Numeric/ComparableTypeAssertions.cs @@ -125,7 +125,7 @@ public AndConstraint BeEquivalentTo(TExpectation expe CompileTimeType = typeof(TExpectation), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); return new AndConstraint((TAssertions)this); } diff --git a/Src/FluentAssertions/Primitives/ObjectAssertions.cs b/Src/FluentAssertions/Primitives/ObjectAssertions.cs index d6bdccfab0..ae2bb62af3 100644 --- a/Src/FluentAssertions/Primitives/ObjectAssertions.cs +++ b/Src/FluentAssertions/Primitives/ObjectAssertions.cs @@ -300,7 +300,7 @@ public AndConstraint BeEquivalentTo(TExpectation expe CompileTimeType = typeof(TExpectation), }; - new EquivalencyValidator().AssertEquality(comparands, context); + new ValidateChildNodeEquivalency().AssertEquality(comparands, context); return new AndConstraint((TAssertions)this); } diff --git a/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs b/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs index 5bd36b35f2..a4c7478d4a 100644 --- a/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs +++ b/Tests/FluentAssertions.Equivalency.Specs/ExtensibilitySpecs.cs @@ -627,7 +627,7 @@ public void When_multiple_steps_are_added_they_should_be_evaluated_first_to_last private class AlwaysFailOnDateTimesEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (comparands.Expectation is DateTime) { @@ -641,13 +641,13 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon private class RelaxingDateTimeEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { if (comparands.Expectation is DateTime time) { ((DateTime)comparands.Subject).Should().BeCloseTo(time, 1.Minutes()); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } return EquivalencyResult.ContinueWithNext; @@ -812,7 +812,7 @@ private class ThrowExceptionEquivalencyStep : IEquivalencyStep where TException : Exception, new() { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { throw new TException(); } @@ -821,16 +821,16 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon private class AlwaysHandleEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } private class NeverHandleEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { return EquivalencyResult.ContinueWithNext; } @@ -839,10 +839,10 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon private class EqualityEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { comparands.Subject.Should().Be(comparands.Expectation, context.Reason.FormattedMessage, context.Reason.Arguments); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } @@ -856,10 +856,10 @@ public DoEquivalencyStep(Action doAction) } public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { doAction(); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } diff --git a/Tests/FluentAssertions.Specs/AssertionOptionsSpecs.cs b/Tests/FluentAssertions.Specs/AssertionOptionsSpecs.cs index 0a2ed6569d..0ffac09bcd 100644 --- a/Tests/FluentAssertions.Specs/AssertionOptionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/AssertionOptionsSpecs.cs @@ -419,11 +419,11 @@ protected override void Dispose(bool disposing) internal class MyEquivalencyStep : IEquivalencyStep { public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, - IEquivalencyValidator nestedValidator) + IValidateChildNodeEquivalency valueChildNodes) { Execute.Assertion.FailWith(GetType().FullName); - return EquivalencyResult.AssertionCompleted; + return EquivalencyResult.EquivalencyProven; } } }