@@ -19,15 +19,8 @@ public string FormatComparison(object? leftValue, object? rightValue)
1919 return AnalyzeCollectionDifferences ( leftList , rightList ) ;
2020 }
2121
22- static List < object ? > MaterializeToList ( object collection )
23- {
24- var result = new List < object ? > ( ) ;
25- foreach ( var item in ( IEnumerable ) collection )
26- {
27- result . Add ( item ) ;
28- }
29- return result ;
30- }
22+ static List < object ? > MaterializeToList ( object collection ) =>
23+ ( ( IEnumerable ) collection ) . Cast < object ? > ( ) . ToList ( ) ;
3124
3225 static string AnalyzeCollectionDifferences ( List < object ? > left , List < object ? > right )
3326 {
@@ -39,10 +32,7 @@ static string AnalyzeCollectionDifferences(List<object?> left, List<object?> rig
3932
4033 var differenceMessage = FindFirstDifference ( left , right ) ;
4134 if ( differenceMessage != null )
42- {
4335 result . Add ( differenceMessage ) ;
44- return string . Join ( "\n " , result ) ;
45- }
4636
4737 var lengthDifferenceMessage = DescribeLengthDifference ( left , right ) ;
4838 if ( lengthDifferenceMessage != null )
@@ -64,15 +54,17 @@ static string AnalyzeCollectionDifferences(List<object?> left, List<object?> rig
6454
6555 static string ? DescribeLengthDifference ( List < object ? > left , List < object ? > right )
6656 {
57+ const int MaxDifferencePreview = 5 ;
58+
6759 if ( left . Count > right . Count )
6860 {
69- var extraElements = left . Skip ( right . Count ) . Take ( 5 ) . ToList ( ) ;
61+ var extraElements = left . Skip ( right . Count ) . Take ( MaxDifferencePreview ) . ToList ( ) ;
7062 return $ " Extra elements: [{ string . Join ( ", " , extraElements . Select ( FormatValue ) ) } ]";
7163 }
7264
7365 if ( right . Count > left . Count )
7466 {
75- var missingElements = right . Skip ( left . Count ) . Take ( 5 ) . ToList ( ) ;
67+ var missingElements = right . Skip ( left . Count ) . Take ( MaxDifferencePreview ) . ToList ( ) ;
7668 return $ " Missing elements: [{ string . Join ( ", " , missingElements . Select ( FormatValue ) ) } ]";
7769 }
7870
0 commit comments