3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Globalization ;
6
7
using System . Linq ;
7
8
using Microsoft . AspNetCore . Internal ;
8
9
using Microsoft . AspNetCore . Testing ;
@@ -38,66 +39,23 @@ public void CreateFromNull()
38
39
Assert . Null ( dict . _dictionaryStorage ) ;
39
40
}
40
41
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
-
67
42
[ Fact ]
68
- public void CreateFromIEnumerableKeyValuePair_CopiesValues ( )
43
+ public void CreateWithCapacityOverDefaultLimit ( )
69
44
{
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 ) ;
72
47
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 ) ;
87
50
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
+ }
93
55
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 ) ;
101
59
}
102
60
103
61
[ Fact ]
@@ -114,23 +72,6 @@ public void CreateFromIEnumerableKeyValuePair_ThrowsExceptionForDuplicateKey()
114
72
$ "An element with the key 'Name' already exists in the { nameof ( AdaptiveCapacityDictionary < string , object ? > ) } .") ;
115
73
}
116
74
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
-
134
75
[ Fact ]
135
76
public void Comparer_IsOrdinalIgnoreCase ( )
136
77
{
0 commit comments