예제 #1
0
        public void ExtendedPropertiesWork()
        {
            var baz = new string[] { "hello", "there" };
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            one["foo"] = "foo value";
            one["bar"] = "bar value";
            one["baz"] = baz;

            one.AddChild(two);
            two.ExtendProperty("baz", new object[] { 2, 3, 4 }); //NOTE: Integers, not strings!

            //Other verification (sanity)
            Assert.AreEqual("foo value", two["foo"]);
            Assert.AreEqual("bar value", two["bar"]);

            Assert.IsFalse(two.HasOwnProperty("foo"));
            Assert.IsFalse(two.HasOwnProperty("bar"));

            //Interesting assertions for this test
            Assert.IsTrue(two.HasOwnProperty("baz"));

            Assert.AreEqual("hello there 2 3 4", String.Join(" ", two["baz"] as IEnumerable<object>));
            Assert.AreEqual("hello there", String.Join(" ", one["baz"] as IEnumerable<object>));
        }
예제 #2
0
        public void AddChildAddsItemToChildrenOfParent()
        {
            var one = new HyperDictionary();
            var two = new HyperDictionary();
            one.AddChild(two);

            var oneChildrenInfo = one.GetType().GetField("children", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var oneChildren = oneChildrenInfo.GetValue(one) as IEnumerable<HyperDictionary>;
            Assert.IsTrue(oneChildren.Contains(two));
        }
예제 #3
0
        public void RemovedPropertiesWork()
        {
            var baz = new Uri("http://blog.tonyheupel.com");
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            one["foo"] = "foo value";
            one["bar"] = "bar value";
            one["baz"] = baz;

            one.AddChild(two);
            two.RemoveProperty("bar");

            //Other verification (sanity)
            Assert.AreEqual("foo value", two["foo"]);
            Assert.AreSame(baz, two["baz"]);

            Assert.IsFalse(two.HasOwnProperty("foo"));
            Assert.IsFalse(two.HasOwnProperty("baz"));

            //Interesting assertions for this test
            Assert.AreEqual("bar value", one["bar"]);
            Assert.IsTrue(two.HasOwnProperty("bar"));

            try
            {
                var bar = two["bar"];
                Assert.Fail("Should not get this far since this object had this property removed");
            }
            catch (IndexOutOfRangeException)
            {
                //Pass!
            }
            catch (Exception)
            {
                Assert.Fail("Raised an exception that was not IndexOutOfRangeException");
            }
        }
예제 #4
0
        public void OverriddenPropertiesWork()
        {
            var baz = new Uri("http://blog.tonyheupel.com");
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            one["foo"] = "foo value";
            one["bar"] = "bar value";
            one["baz"] = baz;

            one.AddChild(two);
            two["bar"] = "two's bar value";

            //Other verification (sanity)
            Assert.AreEqual("foo value", two["foo"]);
            Assert.AreSame(baz, two["baz"]);

            Assert.IsFalse(two.HasOwnProperty("foo"));
            Assert.IsFalse(two.HasOwnProperty("baz"));

            //Interesting assertions for this test
            Assert.AreEqual("two's bar value", two["bar"]);
            Assert.AreEqual("bar value", one["bar"]);
            Assert.IsTrue(two.HasOwnProperty("bar"));
        }
예제 #5
0
        public void InheritedPropertiesWork()
        {
            var baz = new Uri("http://blog.tonyheupel.com");
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            one["foo"] = "foo value";
            one["bar"] = "bar value";
            one["baz"] = baz;

            one.AddChild(two);
            two["whatever"] = "big W";

            Assert.AreEqual("foo value", two["foo"]);
            Assert.AreEqual("bar value", two["bar"]);
            Assert.AreEqual("big W", two["whatever"]);

            Assert.IsFalse(two.HasOwnProperty("foo"));
            Assert.IsFalse(two.HasOwnProperty("bar"));
            Assert.IsFalse(two.HasOwnProperty("baz"));
            Assert.IsTrue(two.HasOwnProperty("whatever"));

            try
            {
                var whatever = one["whatever"];
                Assert.Fail("Not supposed to reach here since this object should not have this property");
            }
            catch (IndexOutOfRangeException)
            {
                //Pass!
            }
        }