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

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

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

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

            return(true);
        }
Ejemplo n.º 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);
        }
        public bool Increment()
        {
            bool success = nextDigit?.Increment() == true;

            if (!success)
            {
                if (index < (length - 1))
                {
                    index++;
                    success = true;
                }
                else
                {
                    index = 0;
                }
            }

            return(success);
        }
Ejemplo n.º 4
0
        public bool Increment()
        {
            bool success = (nextDigit != null) && nextDigit.Increment();

            if (!success)
            {
                if (index < (length - 1))
                {
                    index++;
                    success = true;
                }
                else
                {
                    index = 0;
                }
            }

            return(success);
        }