@@ -57,16 +57,53 @@ public static TheoryData<StringValues> FilledStringValues
57
57
}
58
58
}
59
59
60
+ public static TheoryData < StringValues , string > FilledStringValuesWithExpectedStrings
61
+ {
62
+ get
63
+ {
64
+ return new TheoryData < StringValues , string >
65
+ {
66
+ { default ( StringValues ) , ( string ) null } ,
67
+ { StringValues . Empty , ( string ) null } ,
68
+ { new StringValues ( new string [ ] { } ) , ( string ) null } ,
69
+ { new StringValues ( string . Empty ) , string . Empty } ,
70
+ { new StringValues ( new string [ ] { string . Empty } ) , string . Empty } ,
71
+ { new StringValues ( "abc" ) , "abc" }
72
+ } ;
73
+ }
74
+ }
75
+
76
+ public static TheoryData < StringValues , object > FilledStringValuesWithExpectedObjects
77
+ {
78
+ get
79
+ {
80
+ return new TheoryData < StringValues , object >
81
+ {
82
+ { default ( StringValues ) , ( object ) null } ,
83
+ { StringValues . Empty , ( object ) null } ,
84
+ { new StringValues ( new string [ ] { } ) , ( object ) null } ,
85
+ { new StringValues ( "abc" ) , ( object ) "abc" } ,
86
+ { new StringValues ( "abc" ) , ( object ) new [ ] { "abc" } } ,
87
+ { new StringValues ( new [ ] { "abc" } ) , ( object ) new [ ] { "abc" } } ,
88
+ { new StringValues ( new [ ] { "abc" , "bcd" } ) , ( object ) new [ ] { "abc" , "bcd" } }
89
+ } ;
90
+ }
91
+ }
92
+
60
93
public static TheoryData < StringValues , string [ ] > FilledStringValuesWithExpected
61
94
{
62
95
get
63
96
{
64
97
return new TheoryData < StringValues , string [ ] >
65
98
{
99
+ { default ( StringValues ) , new string [ 0 ] } ,
100
+ { StringValues . Empty , new string [ 0 ] } ,
101
+ { new StringValues ( string . Empty ) , new [ ] { string . Empty } } ,
66
102
{ new StringValues ( "abc" ) , new [ ] { "abc" } } ,
67
103
{ new StringValues ( new [ ] { "abc" } ) , new [ ] { "abc" } } ,
68
104
{ new StringValues ( new [ ] { "abc" , "bcd" } ) , new [ ] { "abc" , "bcd" } } ,
69
105
{ new StringValues ( new [ ] { "abc" , "bcd" , "foo" } ) , new [ ] { "abc" , "bcd" , "foo" } } ,
106
+ { string . Empty , new [ ] { string . Empty } } ,
70
107
{ "abc" , new [ ] { "abc" } } ,
71
108
{ new [ ] { "abc" } , new [ ] { "abc" } } ,
72
109
{ new [ ] { "abc" , "bcd" } , new [ ] { "abc" , "bcd" } } ,
@@ -260,16 +297,29 @@ public void Contains(StringValues stringValues, string[] expected)
260
297
261
298
[ Theory ]
262
299
[ MemberData ( nameof ( FilledStringValuesWithExpected ) ) ]
263
- public void CopyTo ( StringValues stringValues , string [ ] expected )
300
+ public void CopyTo_TooSmall ( StringValues stringValues , string [ ] expected )
264
301
{
265
302
ICollection < string > collection = stringValues ;
266
-
267
303
string [ ] tooSmall = new string [ 0 ] ;
268
- Assert . Throws < ArgumentException > ( ( ) => collection . CopyTo ( tooSmall , 0 ) ) ;
269
304
305
+ if ( collection . Count > 0 )
306
+ {
307
+ Assert . Throws < ArgumentException > ( ( ) => collection . CopyTo ( tooSmall , 0 ) ) ;
308
+ }
309
+ }
310
+
311
+ [ Theory ]
312
+ [ MemberData ( nameof ( FilledStringValuesWithExpected ) ) ]
313
+ public void CopyTo_CorrectSize ( StringValues stringValues , string [ ] expected )
314
+ {
315
+ ICollection < string > collection = stringValues ;
270
316
string [ ] actual = new string [ expected . Length ] ;
271
- Assert . Throws < ArgumentOutOfRangeException > ( ( ) => collection . CopyTo ( actual , - 1 ) ) ;
272
- Assert . Throws < ArgumentException > ( ( ) => collection . CopyTo ( actual , actual . Length + 1 ) ) ;
317
+
318
+ if ( collection . Count > 0 )
319
+ {
320
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => collection . CopyTo ( actual , - 1 ) ) ;
321
+ Assert . Throws < ArgumentException > ( ( ) => collection . CopyTo ( actual , actual . Length + 1 ) ) ;
322
+ }
273
323
collection . CopyTo ( actual , 0 ) ;
274
324
Assert . Equal ( expected , actual ) ;
275
325
}
@@ -302,5 +352,109 @@ public void Concat(StringValues stringValues, string[] array)
302
352
string [ ] expectedAppended = filled . Concat ( array ) . ToArray ( ) ;
303
353
Assert . Equal ( expectedAppended , StringValues . Concat ( new StringValues ( filled ) , stringValues ) ) ;
304
354
}
355
+
356
+ [ Fact ]
357
+ public void Equals_OperatorEqual ( )
358
+ {
359
+ var equalString = "abc" ;
360
+
361
+ var equalStringArray = new string [ ] { equalString } ;
362
+ var equalStringValues = new StringValues ( equalString ) ;
363
+ var stringArray = new string [ ] { equalString , equalString } ;
364
+ var stringValuesArray = new StringValues ( stringArray ) ;
365
+
366
+ Assert . True ( equalStringValues == equalStringValues ) ;
367
+
368
+ Assert . True ( equalStringValues == equalString ) ;
369
+ Assert . True ( equalString == equalStringValues ) ;
370
+
371
+ Assert . True ( equalStringValues == equalStringArray ) ;
372
+ Assert . True ( equalStringArray == equalStringValues ) ;
373
+
374
+ Assert . True ( stringArray == stringValuesArray ) ;
375
+ Assert . True ( stringValuesArray == stringArray ) ;
376
+
377
+ Assert . False ( stringValuesArray == equalString ) ;
378
+ Assert . False ( stringValuesArray == equalStringArray ) ;
379
+ Assert . False ( stringValuesArray == equalStringValues ) ;
380
+ }
381
+
382
+ [ Fact ]
383
+ public void Equals_OperatorNotEqual ( )
384
+ {
385
+ var equalString = "abc" ;
386
+
387
+ var equalStringArray = new string [ ] { equalString } ;
388
+ var equalStringValues = new StringValues ( equalString ) ;
389
+ var stringArray = new string [ ] { equalString , equalString } ;
390
+ var stringValuesArray = new StringValues ( stringArray ) ;
391
+
392
+ Assert . False ( equalStringValues != equalStringValues ) ;
393
+
394
+ Assert . False ( equalStringValues != equalString ) ;
395
+ Assert . False ( equalString != equalStringValues ) ;
396
+
397
+ Assert . False ( equalStringValues != equalStringArray ) ;
398
+ Assert . False ( equalStringArray != equalStringValues ) ;
399
+
400
+ Assert . False ( stringArray != stringValuesArray ) ;
401
+ Assert . False ( stringValuesArray != stringArray ) ;
402
+
403
+ Assert . True ( stringValuesArray != equalString ) ;
404
+ Assert . True ( stringValuesArray != equalStringArray ) ;
405
+ Assert . True ( stringValuesArray != equalStringValues ) ;
406
+ }
407
+
408
+ [ Fact ]
409
+ public void Equals_Instance ( )
410
+ {
411
+ var equalString = "abc" ;
412
+
413
+ var equalStringArray = new string [ ] { equalString } ;
414
+ var equalStringValues = new StringValues ( equalString ) ;
415
+ var stringArray = new string [ ] { equalString , equalString } ;
416
+ var stringValuesArray = new StringValues ( stringArray ) ;
417
+
418
+ Assert . True ( equalStringValues . Equals ( equalStringValues ) ) ;
419
+ Assert . True ( equalStringValues . Equals ( equalString ) ) ;
420
+ Assert . True ( equalStringValues . Equals ( equalStringArray ) ) ;
421
+ Assert . True ( stringValuesArray . Equals ( stringArray ) ) ;
422
+ }
423
+
424
+ [ Theory ]
425
+ [ MemberData ( nameof ( FilledStringValuesWithExpectedObjects ) ) ]
426
+ public void Equals_ObjectEquals ( StringValues stringValues , object obj )
427
+ {
428
+ Assert . True ( stringValues == obj ) ;
429
+ Assert . True ( obj == stringValues ) ;
430
+ }
431
+
432
+ [ Theory ]
433
+ [ MemberData ( nameof ( FilledStringValuesWithExpectedObjects ) ) ]
434
+ public void Equals_ObjectNotEquals ( StringValues stringValues , object obj )
435
+ {
436
+ Assert . False ( stringValues != obj ) ;
437
+ Assert . False ( obj != stringValues ) ;
438
+ }
439
+
440
+ [ Theory ]
441
+ [ MemberData ( nameof ( FilledStringValuesWithExpectedStrings ) ) ]
442
+ public void Equals_String ( StringValues stringValues , string expected )
443
+ {
444
+ var notEqual = new StringValues ( "bcd" ) ;
445
+
446
+ Assert . True ( StringValues . Equals ( stringValues , expected ) ) ;
447
+ Assert . False ( StringValues . Equals ( stringValues , notEqual ) ) ;
448
+ }
449
+
450
+ [ Theory ]
451
+ [ MemberData ( nameof ( FilledStringValuesWithExpected ) ) ]
452
+ public void Equals_StringArray ( StringValues stringValues , string [ ] expected )
453
+ {
454
+ var notEqual = new StringValues ( new [ ] { "bcd" , "abc" } ) ;
455
+
456
+ Assert . True ( StringValues . Equals ( stringValues , expected ) ) ;
457
+ Assert . False ( StringValues . Equals ( stringValues , notEqual ) ) ;
458
+ }
305
459
}
306
460
}
0 commit comments