summaryrefslogtreecommitdiffstats
path: root/SendGrid/Tests/TestTreeNode.cs
diff options
context:
space:
mode:
authorTyler Bischel <tyler.bischel@sendgrid.com>2012-01-10 17:33:13 -0800
committerTyler Bischel <tyler.bischel@sendgrid.com>2012-01-10 17:33:13 -0800
commitb13f35419a29ace0ecaabff02552a0613aa8afe2 (patch)
tree83dba1149b6f90d53935186ee0a601d851a50647 /SendGrid/Tests/TestTreeNode.cs
parent7251a831e634eda2f98885777468b9f5aad6cd00 (diff)
downloadsendgrid-csharp-b13f35419a29ace0ecaabff02552a0613aa8afe2.zip
sendgrid-csharp-b13f35419a29ace0ecaabff02552a0613aa8afe2.tar.gz
sendgrid-csharp-b13f35419a29ace0ecaabff02552a0613aa8afe2.tar.bz2
example project sends email, tree node for filters created, json encoding done, other fixes
Diffstat (limited to 'SendGrid/Tests/TestTreeNode.cs')
-rwxr-xr-xSendGrid/Tests/TestTreeNode.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/SendGrid/Tests/TestTreeNode.cs b/SendGrid/Tests/TestTreeNode.cs
new file mode 100755
index 0000000..4b8a28f
--- /dev/null
+++ b/SendGrid/Tests/TestTreeNode.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using SendGridMail;
+
+namespace Tests
+{
+ [TestFixture]
+ public class TestTreeNode
+ {
+ [Test]
+ public void TestAddToTree()
+ {
+ var test = new Header.FilterNode();
+ test.AddSetting(new List<string>(), "foo");
+ Assert.AreEqual("foo", test.GetLeaf(), "Get the leaf of the first node");
+
+ test = new Header.FilterNode();
+ 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 Header.FilterNode();
+ 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 Header.FilterNode();
+ 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 Header.FilterNode();
+ 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]
+ public void TestToJSON()
+ {
+ var test = new Header.FilterNode();
+ test.AddSetting(new List<string>() { "foo", "bar", "raz" }, "foobar");
+
+ var result = test.ToJson();
+ Assert.AreEqual("{\"foo\":{\"bar\":{\"raz\":\"foobar\"}}}", result);
+
+ test = new Header.FilterNode();
+ 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);
+ }
+ }
+}