コード例 #1
0
        /// <summary>
        /// Displays a single line showing the point in the expected and actual
        /// arrays at which the comparison failed. If the arrays have different
        /// structures or dimensions, both values are shown.
        /// </summary>
        /// <param name="writer">The MessageWriter on which to display</param>
        /// <param name="expected">The expected array</param>
        /// <param name="actual">The actual array</param>
        /// <param name="failurePoint">Index of the failure point in the underlying collections</param>
        /// <param name="indent">The indentation level for the message line</param>
        private void DisplayFailurePoint(MessageWriter writer, ICollection expected, ICollection actual, int failurePoint, int indent)
        {
            Array expectedArray = expected as Array;
            Array actualArray   = actual as Array;

            int expectedRank = expectedArray != null ? expectedArray.Rank : 1;
            int actualRank   = actualArray != null ? actualArray.Rank : 1;

            bool useOneIndex = expectedRank == actualRank;

            if (expectedArray != null && actualArray != null)
            {
                for (int r = 1; r < expectedRank && useOneIndex; r++)
                {
                    if (expectedArray.GetLength(r) != actualArray.GetLength(r))
                    {
                        useOneIndex = false;
                    }
                }
            }

            int[] expectedIndices = MsgUtils.GetArrayIndicesFromCollectionIndex(expected, failurePoint);
            if (useOneIndex)
            {
                writer.WriteMessageLine(indent, ValuesDiffer_1, MsgUtils.GetArrayIndicesAsString(expectedIndices));
            }
            else
            {
                int[] actualIndices = MsgUtils.GetArrayIndicesFromCollectionIndex(actual, failurePoint);
                writer.WriteMessageLine(indent, ValuesDiffer_2,
                                        MsgUtils.GetArrayIndicesAsString(expectedIndices), MsgUtils.GetArrayIndicesAsString(actualIndices));
            }
        }
コード例 #2
0
        /// <summary>
        /// Displays a single line showing the types and sizes of the expected
        /// and actual collections or arrays. If both are identical, the value is
        /// only shown once.
        /// </summary>
        /// <param name="writer">The MessageWriter on which to display</param>
        /// <param name="expected">The expected collection or array</param>
        /// <param name="actual">The actual collection or array</param>
        /// <param name="indent">The indentation level for the message line</param>
        private void DisplayCollectionTypesAndSizes(MessageWriter writer, ICollection expected, ICollection actual, int indent)
        {
            string sExpected = MsgUtils.GetTypeRepresentation(expected);

            if (!(expected is Array))
            {
                sExpected += string.Format(" with {0} elements", expected.Count);
            }

            string sActual = MsgUtils.GetTypeRepresentation(actual);

            if (!(actual is Array))
            {
                sActual += string.Format(" with {0} elements", actual.Count);
            }

            if (sExpected == sActual)
            {
                writer.WriteMessageLine(indent, CollectionType_1, sExpected);
            }
            else
            {
                writer.WriteMessageLine(indent, CollectionType_2, sExpected, sActual);
            }
        }
コード例 #3
0
 private void DisplayStreamDifferences(MessageWriter writer, Stream expected, Stream actual, int depth)
 {
     if (expected.Length == actual.Length)
     {
         long offset = (long)comparer.FailurePoints[depth];
         writer.WriteMessageLine(StreamsDiffer_1, expected.Length, offset);
     }
     else
     {
         writer.WriteMessageLine(StreamsDiffer_2, expected.Length, actual.Length);
     }
 }
コード例 #4
0
        private void DisplayStringDifferences(MessageWriter writer, string expected, string actual)
        {
            int mismatch = MsgUtils.FindMismatchPosition(expected, actual, 0, comparer.IgnoreCase);

            if (expected.Length == actual.Length)
            {
                writer.WriteMessageLine(StringsDiffer_1, expected.Length, mismatch);
            }
            else
            {
                writer.WriteMessageLine(StringsDiffer_2, expected.Length, actual.Length, mismatch);
            }

            writer.DisplayStringDifferences(expected, actual, mismatch, comparer.IgnoreCase, clipStrings);
        }