33
44using System ;
55using System . Collections . Generic ;
6+ using System . Globalization ;
67using System . Linq ;
78using Microsoft . AspNetCore . Internal ;
89using Microsoft . AspNetCore . Testing ;
@@ -38,66 +39,23 @@ public void CreateFromNull()
3839 Assert . Null ( dict . _dictionaryStorage ) ;
3940 }
4041
41- public static KeyValuePair < string , object > [ ] IEnumerableKeyValuePairData
42- {
43- get
44- {
45- return new [ ]
46- {
47- new KeyValuePair < string , object ? > ( "Name" , "James" ) ,
48- new KeyValuePair < string , object ? > ( "Age" , 30 ) ,
49- new KeyValuePair < string , object ? > ( "Address" , new Address ( ) { City = "Redmond" , State = "WA" } )
50- } ;
51- }
52- }
53-
54- public static KeyValuePair < string , string > [ ] IEnumerableStringValuePairData
55- {
56- get
57- {
58- return new [ ]
59- {
60- new KeyValuePair < string , string > ( "First Name" , "James" ) ,
61- new KeyValuePair < string , string > ( "Last Name" , "Henrik" ) ,
62- new KeyValuePair < string , string > ( "Middle Name" , "Bob" )
63- } ;
64- }
65- }
66-
6742 [ Fact ]
68- public void CreateFromIEnumerableKeyValuePair_CopiesValues ( )
43+ public void CreateWithCapacityOverDefaultLimit ( )
6944 {
70- // Arrange & Act
71- var dict = new AdaptiveCapacityDictionary < string , object ? > ( IEnumerableKeyValuePairData , capacity : IEnumerableKeyValuePairData . Length , EqualityComparer < string > . Default ) ;
45+ // The default threshold between array and dictionary is 10. If we created one over that limit it should go directly to a dictionary.
46+ var dict = new AdaptiveCapacityDictionary < string , string > ( capacity : 12 , StringComparer . OrdinalIgnoreCase ) ;
7247
73- // Assert
74- Assert . IsType < KeyValuePair < string , object ? > [ ] > ( dict . _arrayStorage ) ;
75- Assert . Collection (
76- dict . OrderBy ( kvp => kvp . Key ) ,
77- kvp =>
78- {
79- Assert . Equal ( "Address" , kvp . Key ) ;
80- var address = Assert . IsType < Address > ( kvp . Value ) ;
81- Assert . Equal ( "Redmond" , address . City ) ;
82- Assert . Equal ( "WA" , address . State ) ;
83- } ,
84- kvp => { Assert . Equal ( "Age" , kvp . Key ) ; Assert . Equal ( 30 , kvp . Value ) ; } ,
85- kvp => { Assert . Equal ( "Name" , kvp . Key ) ; Assert . Equal ( "James" , kvp . Value ) ; } ) ;
86- }
48+ Assert . Null ( dict . _arrayStorage ) ;
49+ Assert . NotNull ( dict . _dictionaryStorage ) ;
8750
88- [ Fact ]
89- public void CreateFromIEnumerableStringValuePair_CopiesValues ( )
90- {
91- // Arrange & Act
92- var dict = new AdaptiveCapacityDictionary < string , string > ( IEnumerableStringValuePairData , capacity : 3 , StringComparer . OrdinalIgnoreCase ) ;
51+ for ( var i = 0 ; i < 12 ; i ++ )
52+ {
53+ dict [ i . ToString ( CultureInfo . InvariantCulture ) ] = i . ToString ( CultureInfo . InvariantCulture ) ;
54+ }
9355
94- // Assert
95- Assert . IsType < KeyValuePair < string , string > [ ] > ( dict . _arrayStorage ) ;
96- Assert . Collection (
97- dict . OrderBy ( kvp => kvp . Key ) ,
98- kvp => { Assert . Equal ( "First Name" , kvp . Key ) ; Assert . Equal ( "James" , kvp . Value ) ; } ,
99- kvp => { Assert . Equal ( "Last Name" , kvp . Key ) ; Assert . Equal ( "Henrik" , kvp . Value ) ; } ,
100- kvp => { Assert . Equal ( "Middle Name" , kvp . Key ) ; Assert . Equal ( "Bob" , kvp . Value ) ; } ) ;
56+ Assert . Null ( dict . _arrayStorage ) ;
57+ Assert . NotNull ( dict . _dictionaryStorage ) ;
58+ Assert . Equal ( 12 , dict . Count ) ;
10159 }
10260
10361 [ Fact ]
@@ -114,23 +72,6 @@ public void CreateFromIEnumerableKeyValuePair_ThrowsExceptionForDuplicateKey()
11472 $ "An element with the key 'Name' already exists in the { nameof ( AdaptiveCapacityDictionary < string , object ? > ) } .") ;
11573 }
11674
117- [ Fact ]
118- public void CreateFromIEnumerableStringValuePair_ThrowsExceptionForDuplicateKey ( )
119- {
120- // Arrange
121- var values = new List < KeyValuePair < string , string > > ( )
122- {
123- new KeyValuePair < string , string > ( "name" , "Billy" ) ,
124- new KeyValuePair < string , string > ( "Name" , "Joey" ) ,
125- } ;
126-
127- // Act & Assert
128- ExceptionAssert . ThrowsArgument (
129- ( ) => new AdaptiveCapacityDictionary < string , string > ( values , capacity : 3 , StringComparer . OrdinalIgnoreCase ) ,
130- "key" ,
131- $ "An element with the key 'Name' already exists in the { nameof ( AdaptiveCapacityDictionary < string , object > ) } .") ;
132- }
133-
13475 [ Fact ]
13576 public void Comparer_IsOrdinalIgnoreCase ( )
13677 {
0 commit comments