Skip to content

Commit ddeb12f

Browse files
committed
Merge branch 'NH-3831'
2 parents 2b6c398 + f368e4f commit ddeb12f

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@
13521352
<Compile Include="UnionsubclassPolymorphicFormula\Party.cs" />
13531353
<Compile Include="UnionsubclassPolymorphicFormula\Person.cs" />
13541354
<Compile Include="UnionsubclassPolymorphicFormula\UnionSubclassFixture.cs" />
1355+
<Compile Include="UtilityTest\NullableDictionaryFixture.cs" />
13551356
<Compile Include="UtilityTest\IdentitySetFixture.cs" />
13561357
<Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" />
13571358
<Compile Include="UtilityTest\EnumerableExtensionsTests\FirstExtensionTests.cs" />
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
}

src/NHibernate/Util/NullableDictionary.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void Add(TKey key, TValue value)
3737
if (key == null)
3838
{
3939
_nullValue = value;
40+
_gotNullValue = true;
4041
}
4142
else
4243
{

0 commit comments

Comments
 (0)