@@ -52,6 +52,10 @@ public void ToArray_AlwaysCreateACopy()
52
52
53
53
Assert . NotSame ( sourceArray , resultArray ) ;
54
54
Assert . Equal ( sourceArray , resultArray ) ;
55
+
56
+ int [ ] emptySourceArray = Array . Empty < int > ( ) ;
57
+ Assert . NotSame ( emptySourceArray . ToArray ( ) , emptySourceArray . ToArray ( ) ) ;
58
+ Assert . NotSame ( emptySourceArray . Select ( i => i ) . ToArray ( ) , emptySourceArray . Select ( i => i ) . ToArray ( ) ) ;
55
59
}
56
60
57
61
@@ -153,5 +157,44 @@ public void ToArray_FailOnExtremelyLargeCollection()
153
157
var thrownException = Assert . ThrowsAny < Exception > ( ( ) => { largeSeq . ToArray ( ) ; } ) ;
154
158
Assert . True ( thrownException . GetType ( ) == typeof ( OverflowException ) || thrownException . GetType ( ) == typeof ( OutOfMemoryException ) ) ;
155
159
}
160
+
161
+ [ Theory ]
162
+ [ InlineData ( new int [ ] { } , new string [ ] { } ) ]
163
+ [ InlineData ( new int [ ] { 1 } , new string [ ] { "1" } ) ]
164
+ [ InlineData ( new int [ ] { 1 , 2 , 3 } , new string [ ] { "1" , "2" , "3" } ) ]
165
+ public void ToArray_ArrayWhereSelect ( int [ ] sourceIntegers , string [ ] convertedStrings )
166
+ {
167
+ Assert . Equal ( convertedStrings , sourceIntegers . Select ( i => i . ToString ( ) ) . ToArray ( ) ) ;
168
+
169
+ Assert . Equal ( sourceIntegers , sourceIntegers . Where ( i => true ) . ToArray ( ) ) ;
170
+ Assert . Equal ( Array . Empty < int > ( ) , sourceIntegers . Where ( i => false ) . ToArray ( ) ) ;
171
+
172
+ Assert . Equal ( convertedStrings , sourceIntegers . Where ( i => true ) . Select ( i => i . ToString ( ) ) . ToArray ( ) ) ;
173
+ Assert . Equal ( Array . Empty < string > ( ) , sourceIntegers . Where ( i => false ) . Select ( i => i . ToString ( ) ) . ToArray ( ) ) ;
174
+
175
+ Assert . Equal ( convertedStrings , sourceIntegers . Select ( i => i . ToString ( ) ) . Where ( s => s != null ) . ToArray ( ) ) ;
176
+ Assert . Equal ( Array . Empty < string > ( ) , sourceIntegers . Select ( i => i . ToString ( ) ) . Where ( s => s == null ) . ToArray ( ) ) ;
177
+ }
178
+
179
+ [ Theory ]
180
+ [ InlineData ( new int [ ] { } , new string [ ] { } ) ]
181
+ [ InlineData ( new int [ ] { 1 } , new string [ ] { "1" } ) ]
182
+ [ InlineData ( new int [ ] { 1 , 2 , 3 } , new string [ ] { "1" , "2" , "3" } ) ]
183
+ public void ToArray_ListWhereSelect ( int [ ] sourceIntegers , string [ ] convertedStrings )
184
+ {
185
+ var sourceList = new List < int > ( sourceIntegers ) ;
186
+
187
+ Assert . Equal ( convertedStrings , sourceList . Select ( i => i . ToString ( ) ) . ToArray ( ) ) ;
188
+
189
+ Assert . Equal ( sourceList , sourceList . Where ( i => true ) . ToArray ( ) ) ;
190
+ Assert . Equal ( Array . Empty < int > ( ) , sourceList . Where ( i => false ) . ToArray ( ) ) ;
191
+
192
+ Assert . Equal ( convertedStrings , sourceList . Where ( i => true ) . Select ( i => i . ToString ( ) ) . ToArray ( ) ) ;
193
+ Assert . Equal ( Array . Empty < string > ( ) , sourceList . Where ( i => false ) . Select ( i => i . ToString ( ) ) . ToArray ( ) ) ;
194
+
195
+ Assert . Equal ( convertedStrings , sourceList . Select ( i => i . ToString ( ) ) . Where ( s => s != null ) . ToArray ( ) ) ;
196
+ Assert . Equal ( Array . Empty < string > ( ) , sourceList . Select ( i => i . ToString ( ) ) . Where ( s => s == null ) . ToArray ( ) ) ;
197
+ }
198
+
156
199
}
157
200
}
0 commit comments