/
EagerLoadingEnumerableTest.cs
102 lines (93 loc) · 4.17 KB
/
EagerLoadingEnumerableTest.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
namespace Simple.Data.UnitTest
{
using System.Collections.Generic;
using System.Linq;
using Ado;
using NUnit.Framework;
[TestFixture]
public class EagerLoadingEnumerableTest
{
[Test]
public void GroupsObjectAsChildItem()
{
var dict = new Dictionary<string, object>
{
{"foo", "Foo1"},
{"__with1__bar__quux", "Quux1"}
};
var test = new EagerLoadingEnumerable(new[] {dict}).ToList();
Assert.AreEqual(1, test.Count);
var actual = test[0];
Assert.AreEqual("Foo1", actual["foo"]);
var bar = actual["bar"] as IDictionary<string, object>;
Assert.NotNull(bar);
Assert.AreEqual("Quux1", bar["quux"]);
}
[Test]
public void GroupsMultipleObjectsAsChildItems()
{
var dicts = new[]
{
new Dictionary<string, object>
{
{"foo", "Foo1"},
{"__with1__bar__quux", "Quux1"},
{"__with1__wibble__wobble", "Wobble1"}
},
};
var test = new EagerLoadingEnumerable(dicts).ToList();
Assert.AreEqual(1, test.Count);
var actual = test[0];
Assert.AreEqual("Foo1", actual["foo"]);
var bar = actual["bar"] as IDictionary<string, object>;
Assert.NotNull(bar);
Assert.AreEqual("Quux1", bar["quux"]);
var wibble = actual["wibble"] as IDictionary<string, object>;
Assert.NotNull(wibble);
Assert.AreEqual("Wobble1", wibble["wobble"]);
}
[Test]
public void GroupsMultipleObjectsAsChildItemLists()
{
var dicts = new[]
{
new Dictionary<string, object>
{
{"foo", "Foo1"},
{"__withn__bar__quux", "Quux1"},
{"__withn__wibble__wobble", "Wobble1"}
},
new Dictionary<string, object>
{
{"foo", "Foo1"},
{"__withn__bar__quux", "Quux1"},
{"__withn__wibble__wobble", "Wobble2"}
},
new Dictionary<string, object>
{
{"foo", "Foo1"},
{"__withn__bar__quux", "Quux2"},
{"__withn__wibble__wobble", "Wobble1"}
},
new Dictionary<string, object>
{
{"foo", "Foo1"},
{"__withn__bar__quux", "Quux2"},
{"__withn__wibble__wobble", "Wobble2"}
},
};
var test = new EagerLoadingEnumerable(dicts).ToList();
Assert.AreEqual(1, test.Count);
var actual = test[0];
Assert.AreEqual("Foo1", actual["foo"]);
var bar = actual["bar"] as IList<IDictionary<string, object>>;
Assert.NotNull(bar);
Assert.AreEqual("Quux1", bar[0]["quux"]);
Assert.AreEqual("Quux2", bar[1]["quux"]);
var wibble = actual["wibble"] as IList<IDictionary<string, object>>;
Assert.NotNull(wibble);
Assert.AreEqual("Wobble1", wibble[0]["wobble"]);
Assert.AreEqual("Wobble2", wibble[1]["wobble"]);
}
}
}