public void TestAddArray()
 {
     var test = new HeaderSettingsNode();
     test.AddArray(new List<string>{"foo", "bar"}, new string[]{"raz", "blam"});
     var result = test.GetArray("foo", "bar");
     Assert.AreEqual(Enumerable.ToList<string>(result)[0], "raz");
     Assert.AreEqual(Enumerable.ToList<string>(result)[1], "blam");
 }
        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());
        }
        public void AddSetting(List<String> keys, object value)
        {
            if (keys.Count == 0)
            {
                _leaf = value;
            }
            else
            {
                if (_leaf != null || _array != null)
                    throw new ArgumentException("Attempt to overwrite setting");

                string key = keys.First();
                if (!_branches.ContainsKey(key))
                    _branches[key] = new HeaderSettingsNode();

                List<string> remainingKeys = keys.Skip(1).ToList();
                _branches[key].AddSetting(remainingKeys, value);
            }
        }
        public void TestToJSON()
        {
            var test = new HeaderSettingsNode();
            test.AddSetting(new List<string>() { "foo", "bar", "raz" }, "foobar");

            var 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);
        }
示例#5
0
        public void AddSetting(List <String> keys, String value)
        {
            if (keys.Count == 0)
            {
                _leaf = value;
            }
            else
            {
                if (_leaf != null || _array != null)
                {
                    throw new ArgumentException("Attempt to overwrite setting");
                }

                string key = keys.First();
                if (!_branches.ContainsKey(key))
                {
                    _branches[key] = new HeaderSettingsNode();
                }

                List <string> remainingKeys = keys.Skip(1).ToList();
                _branches[key].AddSetting(remainingKeys, value);
            }
        }
        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);
            }
        }
示例#7
0
 /// <summary>
 /// </summary>
 public Header()
 {
     _settings = new HeaderSettingsNode();
 }
示例#8
0
 /// <summary>
 /// </summary>
 public Header()
 {
     _settings = new HeaderSettingsNode();
 }