1
+ using System . Collections . Generic ;
2
+ using NHibernate . Util ;
3
+ using NUnit . Framework ;
4
+
5
+ namespace NHibernate . Test . UtilityTest
6
+ {
7
+ /// <summary>
8
+ /// Tests for NullableDictionary.
9
+ /// </summary>
10
+ [ TestFixture ]
11
+ public class NullableDictionaryFixture
12
+ {
13
+ private NullableDictionary < string , string > nullableDictionary ;
14
+
15
+ private readonly string _itemKey = "key" ;
16
+ private readonly string _itemValue = "value" ;
17
+
18
+ private readonly string _nullItemKey = null ;
19
+ private readonly string _nullItemValue = "null value" ;
20
+
21
+ [ SetUp ]
22
+ public void SetUp ( )
23
+ {
24
+ nullableDictionary = new NullableDictionary < string , string > ( ) ;
25
+ }
26
+
27
+ [ Test ]
28
+ public void AddKeyValue ( )
29
+ {
30
+ //non-null key
31
+ nullableDictionary . Add ( _itemKey , _itemValue ) ;
32
+
33
+ Assert . AreEqual ( 1 , nullableDictionary . Count ) ;
34
+ Assert . AreEqual ( nullableDictionary [ _itemKey ] , _itemValue ) ;
35
+
36
+ //null key
37
+ nullableDictionary . Add ( _nullItemKey , _nullItemValue ) ;
38
+
39
+ Assert . AreEqual ( 2 , nullableDictionary . Count ) ;
40
+ Assert . AreEqual ( nullableDictionary [ _nullItemKey ] , _nullItemValue ) ;
41
+ }
42
+
43
+ [ Test ]
44
+ public void AddUsingIndexer ( )
45
+ {
46
+ //non-null key
47
+ nullableDictionary [ _itemKey ] = _itemValue ;
48
+
49
+ Assert . AreEqual ( 1 , nullableDictionary . Count ) ;
50
+ Assert . AreEqual ( nullableDictionary [ _itemKey ] , _itemValue ) ;
51
+
52
+ //null key
53
+ nullableDictionary [ _nullItemKey ] = _nullItemValue ;
54
+
55
+ Assert . AreEqual ( 2 , nullableDictionary . Count ) ;
56
+ Assert . AreEqual ( nullableDictionary [ _nullItemKey ] , _nullItemValue ) ;
57
+ }
58
+
59
+ [ Test ]
60
+ public void AddKeyValuePair ( )
61
+ {
62
+ //non-null key
63
+ nullableDictionary . Add ( new KeyValuePair < string , string > ( _itemKey , _itemValue ) ) ;
64
+
65
+ Assert . AreEqual ( 1 , nullableDictionary . Count ) ;
66
+ Assert . AreEqual ( nullableDictionary [ _itemKey ] , _itemValue ) ;
67
+
68
+ //null key
69
+ nullableDictionary . Add ( new KeyValuePair < string , string > ( _nullItemKey , _nullItemValue ) ) ;
70
+
71
+ Assert . AreEqual ( 2 , nullableDictionary . Count ) ;
72
+ Assert . AreEqual ( nullableDictionary [ _nullItemKey ] , _nullItemValue ) ;
73
+ }
74
+ }
75
+ }
0 commit comments