public bool Handle(IEquivalencyValidationContext context, IEquivalencyValidator parent,
                           IEquivalencyAssertionOptions config)
        {
            Array expectationAsArray = (Array)context.Expectation;

            if (AreComparable(context, expectationAsArray))
            {
                Digit digit = BuildDigitsRepresentingAllIndices(expectationAsArray);

                do
                {
                    int[]  indices       = digit.GetIndices();
                    object subject       = ((Array)context.Subject).GetValue(indices);
                    string listOfIndices = string.Join(",", indices);
                    object expectation   = expectationAsArray.GetValue(indices);
                    IEquivalencyValidationContext itemContext = context.CreateForCollectionItem(
                        listOfIndices,
                        subject,
                        expectation);

                    parent.AssertEqualityUsing(itemContext);
                }while (digit.Increment());
            }

            return(true);
        }
예제 #2
0
        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);
        }