Exemplo n.º 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>));
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
        public void InheritsFromDoesNotAddItemToChildrenOfParent()
        {
            var one = new HyperDictionary();
            var two = new HyperDictionary();
            two.InheritsFrom(one);

            var oneChildrenInfo = one.GetType().GetField("children", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var oneChildren = oneChildrenInfo.GetValue(one) as IEnumerable<HyperDictionary>;
            Assert.IsFalse(oneChildren.Contains(two));
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
        public void ICollectionValuesRemovedPropertiesWork()
        {
            //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;

            two.InheritsFrom(one);
            two.RemoveProperty("bar", "two's bar value"); //You can still assign a value even though you are removing it

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

            Assert.IsTrue(ones.Contains("foo value"));
            Assert.IsTrue(ones.Contains("bar value"));
            //Assert.IsTrue(ones.Contains(baz));

            Assert.IsTrue(twos.Contains("foo value"));
            //Assert.IsTrue(twos.Contains(baz));

            Assert.IsFalse(twos.Contains("two's bar value"));
            Assert.IsFalse(twos.Contains("bar value"));

            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");
            }
        }
Exemplo n.º 6
0
        public void ICollectionValuesOverriddenPropertiesWork()
        {
            //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;

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

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

            Assert.IsTrue(ones.Contains("foo value"));
            Assert.IsTrue(ones.Contains("bar value"));
            //Assert.IsTrue(ones.Contains(baz));

            Assert.IsTrue(twos.Contains("foo value"));
            //Assert.IsTrue(twos.Contains(baz));

            Assert.IsTrue(twos.Contains("two's bar value"));
            Assert.IsFalse(twos.Contains("bar value"));
        }
Exemplo n.º 7
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));
        }