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"); } }
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; }
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"); } }