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>)); }
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>)); }
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"); } }
public void OwnedPropertiesWork() { var baz = new Uri("http://blog.tonyheupel.com"); var one = new HyperDictionary(); one["foo"] = "foo value"; one["bar"] = "bar value"; one["baz"] = baz; Assert.AreEqual("foo value", one["foo"]); Assert.AreEqual("bar value", one["bar"]); Assert.AreSame(baz, one["baz"]); Assert.IsTrue(one.HasOwnProperty("foo")); Assert.IsTrue(one.HasOwnProperty("bar")); Assert.IsTrue(one.HasOwnProperty("baz")); }
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")); }
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! } }