public void GetFieldsDictionary()
 {
     TestForReflection t = new TestForReflection();
     IDictionary dic = ReflectionUtil.GetFieldsDictionary(t);
     Assert.AreEqual(5, dic.Count);
     Assert.AreEqual(232, dic["integer"], "Couldn't get the integer type field!");
     Assert.AreEqual("FooBar", dic["name"], "Couldn't get the string field");
     Assert.AreEqual("String[]", dic["stringArray"], "Couldn't get the string array field");
 }
 public void RemoveFromArray()
 {
     TestForReflection t = new TestForReflection();
     FieldInfo fi = t.GetType().GetField("stringArray");
     ReflectionUtil.RemoveFromArray(fi, t, 0);
     Assert.AreEqual(1, t.stringArray.Length, "Didn't remove from array!");
     Assert.AreEqual("rahien", t.stringArray[0], "Removed the wrong element");
 }
        public void SetName()
        {
            NamedObject n = new NamedObject();
            ReflectionUtil.SetName(n, "New Name");
            Assert.AreEqual("New Name", n.name, "Can't set the name when it's a field");
            TestForReflection t = new TestForReflection();
            ReflectionUtil.SetName(t, "New Name (2)");
            Assert.AreEqual("New Name (2)", t.Name, "Can't set the name when it's a property");

            //This to check that we don't have an exception on fields without names
            ReflectionUtil.SetName(new object(), "object's name");
        }
 public void GetPropertyValueWhenCannotRead()
 {
     TestForReflection t = new TestForReflection();
     object o = ReflectionUtil.GetPropertyValue(t, "SetValue");
     Assert.AreEqual("No value", (string)o, "Property with set only return a valid value.");
 }
 public void GetPropertyValueStr()
 {
     TestForReflection t = new TestForReflection();
     Assert.AreEqual(t.Value, ReflectionUtil.GetPropertyValue(t, "Value"), "Get property value return invalid value");
 }
 public void GetPropertyValueArray()
 {
     TestForReflection t = new TestForReflection();
     object o = ReflectionUtil.GetPropertyValue(t, "StringArray");
     Assert.AreEqual(typeof(string[]), o.GetType());
 }
 public void GetPropertiesDictionary_NullProperty()
 {
     TestForReflection tfr = new TestForReflection();
     IDictionary props = ReflectionUtil.GetPropertiesDictionary(tfr);
     Assert.AreEqual("null", props["NullProperty"]);
 }
 public void GetPropertiesDictionary()
 {
     TestForReflection t = new TestForReflection();
     IDictionary dic = ReflectionUtil.GetPropertiesDictionary(t);
     Assert.AreEqual(5, dic.Count);
     Assert.AreEqual("232", dic["Integer"], "Couldn't get the integer type property!");
     Assert.AreEqual("FooBar", dic["Name"], "Couldn't get the string property");
     Assert.AreEqual(typeof(String[]), dic["StringArray"].GetType());
 }