@@ -393,6 +393,11 @@ public void AlreadyInitializedListInterfaceBinding()
393
393
Assert . Equal ( "val1" , list [ 2 ] ) ;
394
394
Assert . Equal ( "val2" , list [ 3 ] ) ;
395
395
Assert . Equal ( "valx" , list [ 4 ] ) ;
396
+
397
+ // Ensure expandability of the returned list
398
+ options . AlreadyInitializedListInterface . Add ( "ExtraItem" ) ;
399
+ Assert . Equal ( 6 , options . AlreadyInitializedListInterface . Count ) ;
400
+ Assert . Equal ( "ExtraItem" , options . AlreadyInitializedListInterface [ 5 ] ) ;
396
401
}
397
402
398
403
[ Fact ]
@@ -1067,7 +1072,7 @@ public void CanBindInitializedIEnumerableAndTheOriginalItemsAreNotMutated()
1067
1072
{ "AlreadyInitializedIEnumerableInterface:1" , "val1" } ,
1068
1073
{ "AlreadyInitializedIEnumerableInterface:2" , "val2" } ,
1069
1074
{ "AlreadyInitializedIEnumerableInterface:x" , "valx" } ,
1070
-
1075
+
1071
1076
{ "ICollectionNoSetter:0" , "val0" } ,
1072
1077
{ "ICollectionNoSetter:1" , "val1" } ,
1073
1078
} ;
@@ -1098,6 +1103,11 @@ public void CanBindInitializedIEnumerableAndTheOriginalItemsAreNotMutated()
1098
1103
Assert . Equal ( 2 , options . ICollectionNoSetter . Count ) ;
1099
1104
Assert . Equal ( "val0" , options . ICollectionNoSetter . ElementAt ( 0 ) ) ;
1100
1105
Assert . Equal ( "val1" , options . ICollectionNoSetter . ElementAt ( 1 ) ) ;
1106
+
1107
+ // Ensure expandability of the returned collection
1108
+ options . ICollectionNoSetter . Add ( "ExtraItem" ) ;
1109
+ Assert . Equal ( 3 , options . ICollectionNoSetter . Count ) ;
1110
+ Assert . Equal ( "ExtraItem" , options . ICollectionNoSetter . ElementAt ( 2 ) ) ;
1101
1111
}
1102
1112
1103
1113
[ Fact ]
@@ -1218,6 +1228,11 @@ public void CanBindUninitializedICollection()
1218
1228
Assert . Equal ( "val1" , array [ 1 ] ) ;
1219
1229
Assert . Equal ( "val2" , array [ 2 ] ) ;
1220
1230
Assert . Equal ( "valx" , array [ 3 ] ) ;
1231
+
1232
+ // Ensure expandability of the returned collection
1233
+ options . ICollection . Add ( "ExtraItem" ) ;
1234
+ Assert . Equal ( 5 , options . ICollection . Count ) ;
1235
+ Assert . Equal ( "ExtraItem" , options . ICollection . ElementAt ( 4 ) ) ;
1221
1236
}
1222
1237
1223
1238
[ Fact ]
@@ -1246,6 +1261,11 @@ public void CanBindUninitializedIList()
1246
1261
Assert . Equal ( "val1" , list [ 1 ] ) ;
1247
1262
Assert . Equal ( "val2" , list [ 2 ] ) ;
1248
1263
Assert . Equal ( "valx" , list [ 3 ] ) ;
1264
+
1265
+ // Ensure expandability of the returned list
1266
+ options . IList . Add ( "ExtraItem" ) ;
1267
+ Assert . Equal ( 5 , options . IList . Count ) ;
1268
+ Assert . Equal ( "ExtraItem" , options . IList [ 4 ] ) ;
1249
1269
}
1250
1270
1251
1271
[ Fact ]
@@ -1602,5 +1622,61 @@ private class OptionsWithInterdependentProperties
1602
1622
public IEnumerable < int > FilteredConfigValues => ConfigValues . Where ( p => p > 10 ) ;
1603
1623
public IEnumerable < int > ConfigValues { get ; set ; }
1604
1624
}
1625
+
1626
+ [ Fact ]
1627
+ public void DifferentDictionaryBindingCasesTest ( )
1628
+ {
1629
+ var dic = new Dictionary < string , string > ( ) { { "key" , "value" } } ;
1630
+ var config = new ConfigurationBuilder ( )
1631
+ . AddInMemoryCollection ( dic )
1632
+ . Build ( ) ;
1633
+
1634
+ Assert . Single ( config . Get < Dictionary < string , string > > ( ) ) ;
1635
+ Assert . Single ( config . Get < IDictionary < string , string > > ( ) ) ;
1636
+ Assert . Single ( config . Get < ExtendedDictionary < string , string > > ( ) ) ;
1637
+ Assert . Single ( config . Get < ImplementerOfIDictionaryClass < string , string > > ( ) ) ;
1638
+ }
1639
+
1640
+ public class ImplementerOfIDictionaryClass < TKey , TValue > : IDictionary < TKey , TValue >
1641
+ {
1642
+ private Dictionary < TKey , TValue > _dict = new ( ) ;
1643
+
1644
+ public TValue this [ TKey key ] { get => _dict [ key ] ; set => _dict [ key ] = value ; }
1645
+
1646
+ public ICollection < TKey > Keys => _dict . Keys ;
1647
+
1648
+ public ICollection < TValue > Values => _dict . Values ;
1649
+
1650
+ public int Count => _dict . Count ;
1651
+
1652
+ public bool IsReadOnly => false ;
1653
+
1654
+ public void Add ( TKey key , TValue value ) => _dict . Add ( key , value ) ;
1655
+
1656
+ public void Add ( KeyValuePair < TKey , TValue > item ) => _dict . Add ( item . Key , item . Value ) ;
1657
+
1658
+ public void Clear ( ) => _dict . Clear ( ) ;
1659
+
1660
+ public bool Contains ( KeyValuePair < TKey , TValue > item ) => _dict . Contains ( item ) ;
1661
+
1662
+ public bool ContainsKey ( TKey key ) => _dict . ContainsKey ( key ) ;
1663
+
1664
+ public void CopyTo ( KeyValuePair < TKey , TValue > [ ] array , int arrayIndex ) => throw new NotImplementedException ( ) ;
1665
+
1666
+ public IEnumerator < KeyValuePair < TKey , TValue > > GetEnumerator ( ) => _dict . GetEnumerator ( ) ;
1667
+
1668
+ public bool Remove ( TKey key ) => _dict . Remove ( key ) ;
1669
+
1670
+ public bool Remove ( KeyValuePair < TKey , TValue > item ) => _dict . Remove ( item . Key ) ;
1671
+
1672
+ public bool TryGetValue ( TKey key , out TValue value ) => _dict . TryGetValue ( key , out value ) ;
1673
+
1674
+ System . Collections . IEnumerator System . Collections . IEnumerable . GetEnumerator ( ) => _dict . GetEnumerator ( ) ;
1675
+ }
1676
+
1677
+ public class ExtendedDictionary < TKey , TValue > : Dictionary < TKey , TValue >
1678
+ {
1679
+
1680
+ }
1605
1681
}
1606
1682
}
0 commit comments