/// <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 static 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, Resources.ValuesDiffer_1, MsgUtils.GetArrayIndicesAsString( expectedIndices ) ); } else { int[] actualIndices = MsgUtils.GetArrayIndicesFromCollectionIndex( actual, failurePoint ); writer.WriteMessageLine( indent, Resources.ValuesDiffer_2, MsgUtils.GetArrayIndicesAsString( expectedIndices ), MsgUtils.GetArrayIndicesAsString( actualIndices ) ); } }
/// <summary> /// Displays the stream differences. /// </summary> /// <param name="writer">The writer.</param> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> /// <param name="depth">The depth.</param> private void DisplayStreamDifferences( MessageWriter writer, Stream expected, Stream actual, int depth ) { if ( expected.Length == actual.Length ) { long offset = _failurePoints[depth]; writer.WriteMessageLine( Resources.StreamsDiffer_1, expected.Length, offset ); } else { writer.WriteMessageLine( Resources.StreamsDiffer_2, expected.Length, actual.Length ); } }
/// <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 static void DisplayCollectionTypesAndSizes( MessageWriter writer, ICollection expected, ICollection actual, int indent ) { string sExpected = MsgUtils.GetTypeRepresentation( expected ); if ( !( expected is Array ) ) { sExpected += string.Format( CultureInfo.CurrentCulture, Resources.WithElements_1, expected.Count ); } string sActual = MsgUtils.GetTypeRepresentation( actual ); if ( !( actual is Array ) ) { sActual += string.Format( CultureInfo.CurrentCulture, Resources.WithElements_1, expected.Count ); } if ( sExpected == sActual ) { writer.WriteMessageLine( indent, Resources.CollectionType_1, sExpected ); } else { writer.WriteMessageLine( indent, Resources.CollectionType_2, sExpected, sActual ); } }
/// <summary> /// Displays the string differences. /// </summary> /// <param name="writer">The writer.</param> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> private void DisplayStringDifferences( MessageWriter writer, string expected, string actual ) { int mismatch = MsgUtils.FindMismatchPosition( expected, actual, 0, CaseInsensitive ); if ( expected.Length == actual.Length ) { writer.WriteMessageLine( Resources.StringsDiffer_1, expected.Length, mismatch ); } else { writer.WriteMessageLine( Resources.StringsDiffer_2, expected.Length, actual.Length, mismatch ); } writer.DisplayStringDifferences( expected, actual, mismatch, CaseInsensitive ); }