示例#1
0
        public void ThreeLevelPropertiesWork()
        {
            var baz = new string[] { "hello", "there" };
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            var twoPrime = new HyperDictionary("two'");
            var three = new HyperDictionary("three");
            one["foo"] = "foo value";
            one["bar"] = "bar value";
            one["baz"] = baz;

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

            three.InheritsFrom(two);
            three["bar"] = "three bar value";
            three.ExtendProperty("baz", new object[] { "three-baz" });

            //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.AreSame(one["foo"], twoPrime["foo"]);
            Assert.AreSame(one["bar"], twoPrime["bar"]);
            Assert.AreSame(one["baz"], twoPrime["baz"]);

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

            Assert.AreEqual("foo value", three["foo"]);
            Assert.AreEqual("three bar value", three["bar"]);

            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>));
            Assert.AreEqual("hello there 2 3 4 three-baz", String.Join(" ", three["baz"] as IEnumerable<object>));
        }
示例#2
0
        public void ICollectionValuesThreeLevelPropertiesWork()
        {
            var baz = new string[] { "hello", "there" };
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            var twoPrime = new HyperDictionary("two'");
            var three = new HyperDictionary("three");
            one["foo"] = "foo value";
            one["bar"] = "bar value";
            one["baz"] = baz;

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

            three.InheritsFrom(two);
            three["bar"] = "three bar value";
            three.ExtendProperty("baz", new object[] { "three-baz" });

            var ones = one.Values;
            var twos = two.Values;
            var twoPrimes = twoPrime.Values;
            var threes = three.Values;

            //Other verification (sanity)
            Assert.IsTrue(twos.Contains("foo value"));
            Assert.IsTrue(twos.Contains("bar value"));

            //Interesting assertions for this test
            Assert.IsTrue(twoPrimes.Contains("foo value"));
            Assert.IsTrue(twoPrimes.Contains("bar value"));
            Assert.IsTrue(twoPrimes.Contains(baz));

            Assert.IsTrue(threes.Contains("foo value"));
            Assert.IsTrue(threes.Contains("three bar value"));
            Assert.IsFalse(threes.Contains("bar value"));

            //Elements are in order of keys added, starting with the child and then moving up
            var ob = ones.ElementAt(2) as IEnumerable<object>;
            var tb = twos.ElementAt(0) as IEnumerable<object>;
            var tpb = twoPrimes.ElementAt(2) as IEnumerable<object>;
            var thb = threes.ElementAt(1) as IEnumerable<object>;
            Assert.AreEqual("hello there 2 3 4", String.Join(" ", tb));
            Assert.AreEqual("hello there", String.Join(" ", ob));
            Assert.AreEqual("hello there 2 3 4 three-baz", String.Join(" ", thb));
        }