示例#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
        private static dynamic InhertiableHyperDictionary()
        {
            Console.WriteLine("Using HyperDictionary to show dictionary inheritance\n==================================================");
            var top = new HyperDictionary("top");
            top["eyes"] = "brown";
            top["hair"] = "pointy";

            var second = new HyperDictionary("second");
            second.InheritsFrom(top);
            second["hair"] = "straight";

            Console.WriteLine("top[\"eyes\"]:\t{0}", top["eyes"]);
            Console.WriteLine("top[\"hair\"]:\t{0}", top["hair"]);
            Console.WriteLine("second[\"eyes\"]:\t{0}", second["eyes"]);
            Console.WriteLine("second[\"hair\"]:\t{0}", second["hair"]);

            //Extends and removes using an IEnumerable<object> value
            top["things"] = new string[] { "first thing", "second thing" };

            var third = new HyperDictionary("third");
            third.InheritsFrom(second);
            third.RemoveProperty("hair");
            third.ExtendProperty("things", new object[] { 3, 4, 5 });

            //Output members of third - note the absence of "hair" member
            Console.Write("third members:\n");
            foreach (object o in third)
            {
                Console.WriteLine(o);
            }
            Console.WriteLine();

            // Output the extended list of items in "things",
            // some from top and some from third.
            // And notice: DIFFERENT DATA TYPES!
            Console.Write("third things:\t");
            var things = third["things"] as IEnumerable<object>;
            foreach (object thing in things)
            {
                Console.Write(" | " + thing.ToString());
            }
            Console.Write(" | ");
            Console.WriteLine();

            Console.WriteLine("Making sure TryGetProperty works...should have 'not set' as the next value...");
            object stomach;
            if (third.TryGetProperty("stomach", out stomach)) Console.WriteLine("third\tstomach:\t{0}", stomach);
            else Console.WriteLine("not set - third.stomach");

            Console.WriteLine();
            Pause();

            return third;
        }
示例#3
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>));
        }
示例#4
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));
        }
示例#5
0
        public void ICollectionValuesExtendedPropertiesWork()
        {
            var baz = new string[] { "hello", "there" };
            var one = new HyperDictionary("one");
            var two = new HyperDictionary("two");
            one["baz"] = baz;

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

            var ones = one.Values;
            var twos = two.Values;

            Assert.IsTrue(ones.Contains(baz));
            var tb = twos.ElementAt(0) as IEnumerable<object>;
            Assert.AreEqual("hello there 2 3 4", String.Join(" ", tb));
        }