forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryClonerTest.cs
More file actions
54 lines (46 loc) · 2.01 KB
/
DictionaryClonerTest.cs
File metadata and controls
54 lines (46 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace Simple.Data.UnitTest
{
using System.Collections.Generic;
using NUnit.Framework;
[TestFixture]
public class DictionaryClonerTest
{
[Test]
public void ClonedDictionaryShouldBeOfSameType()
{
var target = new DictionaryCloner();
var original = new SortedDictionary<string, object>();
var clone = target.CloneDictionary(original);
Assert.AreNotSame(original, clone);
Assert.IsInstanceOf<SortedDictionary<string,object>>(clone);
}
[Test]
public void NestedDictionaryShouldBeCloned()
{
var target = new DictionaryCloner();
var nested = new Dictionary<string, object> { { "Answer", 42 } };
var original = new Dictionary<string, object> { { "Nested", nested } };
var clone = target.CloneDictionary(original);
Assert.IsTrue(clone.ContainsKey("Nested"));
var nestedClone = clone["Nested"] as Dictionary<string, object>;
Assert.IsNotNull(nestedClone);
Assert.AreNotSame(nested, nestedClone);
Assert.IsTrue(nestedClone.ContainsKey("Answer"));
Assert.AreEqual(42, nestedClone["Answer"]);
}
[Test]
public void NestedDictionariesShouldBeCloned()
{
var target = new DictionaryCloner();
var nested = new List<Dictionary<string, object>> { new Dictionary<string, object> { { "Answer", 42 } } };
var original = new Dictionary<string, object> { { "Nested", nested } };
var clone = target.CloneDictionary(original);
Assert.IsTrue(clone.ContainsKey("Nested"));
var nestedClone = clone["Nested"] as List<Dictionary<string, object>>;
Assert.IsNotNull(nestedClone);
Assert.AreNotSame(nested, nestedClone);
Assert.IsTrue(nestedClone.Count == 1);
Assert.AreEqual(42, nestedClone[0]["Answer"]);
}
}
}