private static bool AreComparable(Comparands comparands, Array expectationAsArray) { return (IsArray(comparands.Subject) && HaveSameRank(comparands.Subject, expectationAsArray) && HaveSameDimensions(comparands.Subject, expectationAsArray)); }
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator) { Array expectationAsArray = comparands.Expectation as Array; if (expectationAsArray is null || expectationAsArray?.Rank == 1) { return(EquivalencyResult.ContinueWithNext); } if (AreComparable(comparands, expectationAsArray)) { if (expectationAsArray.Length == 0) { return(EquivalencyResult.AssertionCompleted); } Digit digit = BuildDigitsRepresentingAllIndices(expectationAsArray); do { int[] indices = digit.GetIndices(); object subject = ((Array)comparands.Subject).GetValue(indices); string listOfIndices = string.Join(",", indices); object expectation = expectationAsArray.GetValue(indices); IEquivalencyValidationContext itemContext = context.AsCollectionItem <object>(listOfIndices); nestedValidator.RecursivelyAssertEquality(new Comparands(subject, expectation, typeof(object)), itemContext); }while (digit.Increment()); } return(EquivalencyResult.AssertionCompleted); }
public void RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context) { var scope = AssertionScope.Current; if (ShouldCompareMembersThisDeep(context.CurrentNode, context.Options, scope)) { UpdateScopeWithReportableContext(scope, comparands, context.CurrentNode); if (!context.IsCyclicReference(comparands.Expectation)) { RunStepsUntilEquivalencyIsProven(comparands, context); } } }
public void AssertEquality(Comparands comparands, EquivalencyValidationContext context) { using var scope = new AssertionScope(); scope.AssumeSingleCaller(); scope.AddReportable("configuration", context.Options.ToString()); scope.BecauseOf(context.Reason); RecursivelyAssertEquality(comparands, context); if (context.TraceWriter is not null) { scope.AddReportable("trace", context.TraceWriter.ToString()); } }
private void RunStepsUntilEquivalencyIsProven(Comparands comparands, IEquivalencyValidationContext context) { foreach (IEquivalencyStep step in AssertionOptions.EquivalencyPlan) { var result = step.Handle(comparands, context, this); context.Tracer.WriteLine(_ => $"Step {step.GetType().Name} returned {result}"); if (result == EquivalencyResult.AssertionCompleted) { return; } } throw new NotImplementedException( $"Do not know how to compare {comparands.Subject} and {comparands.Expectation}. Please report an issue through https://www.fluentassertions.com."); }
private static void UpdateScopeWithReportableContext(AssertionScope scope, Comparands comparands, INode currentNode) { scope.Context = new Lazy <string>(() => currentNode.Description); scope.TrackComparands(comparands.Subject, comparands.Expectation); }