public void GetKeys() { // create test object TestObjForNames test = new TestObjForNames(); // test getting public + private keys { var keys = Mirrors.Mirrors.Keys(test, false); HashSet <string> expectedKeys = new HashSet <string>(new string[] { "pub_field", "prv_field", "pub_prop", "prv_prop", "pub_func", "prv_func", "ToString" }); foreach (var mustHave in expectedKeys) { Assert.IsTrue(keys.Contains(mustHave), "Missing key: " + mustHave); } } // test getting public keys { var keys = Mirrors.Mirrors.Keys(test, true); HashSet <string> expectedKeys = new HashSet <string>(new string[] { "pub_field", "pub_prop", "pub_func", "ToString" }); foreach (var mustHave in expectedKeys) { Assert.IsTrue(keys.Contains(mustHave), "Missing key: " + mustHave); } Assert.IsFalse(keys.Contains("prv_field"), "prv_field should not appear when asking only public members!"); } // test getting public + private keys, only declared { var keys = Mirrors.Mirrors.Keys(test, false, true); HashSet <string> expectedKeys = new HashSet <string>(new string[] { "pub_field", "prv_field", "pub_prop", "prv_prop", "pub_func", "prv_func" }); foreach (var mustHave in expectedKeys) { Assert.IsTrue(keys.Contains(mustHave), "Missing key: " + mustHave); } Assert.IsFalse(keys.Contains("ToString"), "ToString should not appear when asking only declared members!"); } // test getting public keys, only declared { var keys = Mirrors.Mirrors.Keys(test, true, true); HashSet <string> expectedKeys = new HashSet <string>(new string[] { "pub_field", "pub_prop", "pub_func" }); foreach (var mustHave in expectedKeys) { Assert.IsTrue(keys.Contains(mustHave), "Missing key: " + mustHave); } Assert.IsFalse(keys.Contains("prv_field"), "prv_field should not appear when asking only public members!"); Assert.IsFalse(keys.Contains("ToString"), "ToString should not appear when asking only declared members!"); } }
public void TestInvoke() { TestObjForNames test = new TestObjForNames(); Assert.AreEqual(Mirrors.Mirrors.Invoke(test, "pub_func"), test.pub_func()); }
public void TestParseEnum() { TestObjForNames test = new TestObjForNames(); Assert.AreEqual(Mirrors.Mirrors.ParseEnum <TestEnum>("Val1"), TestEnum.Val1); }
public void GetClassname() { TestObjForNames test = new TestObjForNames(); Assert.AreEqual(Mirrors.Mirrors.ClassName(test), "TestObjForNames"); }