-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathTestTreeNode.cs
More file actions
103 lines (88 loc) · 4.18 KB
/
Copy pathTestTreeNode.cs
File metadata and controls
103 lines (88 loc) · 4.18 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
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
103
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace SendGrid.SmtpApi.HeaderTests
{
[TestFixture]
public class TestTreeNode
{
[Test]
public void TestAddArray()
{
var test = new HeaderSettingsNode();
test.AddArray(new List<string> { "foo", "bar" }, new[] { "raz", "blam" });
IEnumerable<object> result = test.GetArray("foo", "bar");
IList<object> enumerable = result as IList<object> ?? result.ToList();
// Fix for possible multiple enumerations
Assert.AreEqual(enumerable.ToList()[0], "raz");
Assert.AreEqual(enumerable.ToList()[1], "blam");
}
[Test]
public void TestAddSetting()
{
var test = new HeaderSettingsNode();
test.AddSetting(new List<string>(), "foo");
Assert.AreEqual("foo", test.GetLeaf(), "Get the leaf of the first node");
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo" }, "bar");
Assert.AreEqual("bar", test.GetSetting(new List<string> { "foo" }),
"Get the item in the first branch 'foo', make sure its set to 'bar'");
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo" }, "bar");
Assert.AreEqual("bar", test.GetSetting("foo"),
"tests the convienence get setting function that omits the lists stuff...");
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo", "bar", "raz" }, "foobar");
Assert.AreEqual("foobar", test.GetSetting("foo", "bar", "raz"),
"tests a tree that is multiple branches deep");
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo", "bar", "raz" }, "foobar");
test.AddSetting(new List<string> { "barfoo", "barbar", "barraz" }, "barfoobar");
Assert.AreEqual("foobar", test.GetSetting("foo", "bar", "raz"), "tests a tree that has multiple branches");
Assert.AreEqual("barfoobar", test.GetSetting("barfoo", "barbar", "barraz"), "tests the other branch");
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo" }, "bar");
try
{
test.AddSetting(new List<string> { "foo", "raz" }, "blam");
Assert.Fail("exception not thrown");
}
catch (ArgumentException ex)
{
Assert.AreEqual("Attempt to overwrite setting", ex.Message);
}
}
[Test]
public void TestIsEmpty()
{
var test = new HeaderSettingsNode();
Assert.IsTrue(test.IsEmpty());
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo" }, "bar");
Assert.IsFalse(test.IsEmpty());
test = new HeaderSettingsNode();
test.AddArray(new List<string> { "raz" }, new List<string> { "blam" });
Assert.IsFalse(test.IsEmpty());
}
[Test]
public void TestToJson()
{
var test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo", "bar", "raz" }, "foobar");
string result = test.ToJson();
Assert.AreEqual("{\"foo\" : {\"bar\" : {\"raz\" : \"foobar\"}}}", result);
test = new HeaderSettingsNode();
test.AddSetting(new List<string> { "foo", "bar", "raz" }, "foobar");
test.AddSetting(new List<string> { "barfoo", "barbar", "barraz" }, "barfoobar");
result = test.ToJson();
Assert.AreEqual(
"{\"foo\" : {\"bar\" : {\"raz\" : \"foobar\"}},\"barfoo\" : {\"barbar\" : {\"barraz\" : \"barfoobar\"}}}",
result);
test = new HeaderSettingsNode();
test.AddArray(new List<string> { "foo" }, new List<string> { "bar", "raz" });
result = test.ToJson();
Assert.AreEqual("{\"foo\" : [\"bar\",\"raz\"]}", result);
}
}
}