public MFTestResults SystemReflectionType_ObjectGetType_Test0()
        {
            bool fRes = true;

            ///
            /// Test object.GetType method for various types (including
            /// reflection types and arrays of reflection types).
            /// 
            object o = (object)1;
            fRes &= (o.GetType() == typeof(int));

            o = (object)typeof(Type);
            fRes &= o.GetType() == typeof(Type).GetType();

            o = AppDomain.CurrentDomain.GetAssemblies();
            fRes &= o.GetType() == typeof(Assembly[]);

            o = new TestClass();
            fRes &= o.GetType() == typeof(TestClass);

            o = new TestStruct();
            fRes &= o.GetType() == typeof(TestStruct);

            o = new MyDelegate(MyDelegateImpl);
            fRes &= o.GetType() == typeof(MyDelegate);

            o = (new MyDelegate(MyDelegateImpl)).Method;
            Debug.Print("object (MethodInfo) GetType: " + o.GetType().ToString());

            MethodInfo mi = typeof(SystemReflectionTypeTests).GetMethod("MyDelegateImpl", BindingFlags.Static | BindingFlags.NonPublic);
            fRes &= o.GetType() == mi.GetType();

            return fRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
Beispiel #2
0
        public void Test()
        {
            TestClass o = new TestClass();
            var p = o.GetType().GetProperty("A");
            p.SetValue(o, 10,null);

            int value = (int)p.Get(o);

            Assert.IsTrue(value == 10);
        }
Beispiel #3
0
        public void Test()
        {
            TestClass o = new TestClass();
            var field = o.GetType().GetField("A", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField | BindingFlags.GetField);
            field.SetValue(o, 10);

            int value = (int)field.Get(o);

            Assert.IsTrue(value == 10);
        }
Beispiel #4
0
        public void BindToClassProperty()
        {
            var tc = new TestClass();

            var classProp = new BoundMember<int>(tc, tc.GetType().GetProperty("Property"));

            tc.Property = 5;
            Assert.AreEqual(5, classProp.Value);
            classProp.Value = 10;
            Assert.AreEqual(10, tc.Property);
        }
Beispiel #5
0
        public void BindToClassField()
        {
            var tc = new TestClass();

            var classField = new BoundMember<int>(tc, tc.GetType().GetField("Field"));

            tc.Field = 5;
            Assert.AreEqual(5, classField.Value);
            classField.Value = 10;
            Assert.AreEqual(10, tc.Field);
        }
        public void GetCacherTest()
        {
            var cf = new MemoryCacherFactory(new StubCachePolicyFactory(), new ObjectCacheFactory());
            var ph = new PropertyHelper(cf);
            var tci = new TestClassImpl
            {
                I = 1
            };
            var tc = new TestClass
            {
                I = 2
            };

            var r1 = ph.Get(tci.GetType().GetProperty("I"), tci);
            var r2 = ph.Get(tc.GetType().GetProperty("I"), tc);

            Assert.AreEqual(tci.I, r1);
            Assert.AreEqual(tc.I, r2);
        }
        public MFTestResults SystemReflectionType_RuntimeType_Test1()
        {
            bool fRes = true;
            ArrayList list = new ArrayList();
            int i = 0;

            ///
            /// Test the RuntimeType class members
            /// 
            TestClass cls = new TestClass();

            // Test Type members for a class type
            Type t = cls.GetType();
            Assembly asm = t.Assembly;
            list.Add(asm);
            fRes &= ((Assembly)list[i]).GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= asm.GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= t.Name == "TestClass";
            fRes &= t.FullName == "Microsoft.SPOT.Platform.Tests.SystemReflectionTypeTests+TestClass";
            fRes &= t.BaseType == typeof(object);
            fRes &= t.GetElementType() == null;

            MethodInfo []mis = t.GetMethods();
            fRes &= mis[0].Name == "Method1";
            mis = t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            fRes &= mis[0].Name == "Method2";
            fRes &= t.GetMethod("Method1") != null;
            fRes &= t.GetMethod("Method2", BindingFlags.Instance | BindingFlags.NonPublic) != null;
            
            FieldInfo[] fis = t.GetFields();
            fRes &= fis[0].Name == "m_Field1";
            fis = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            fRes &= fis[0].Name == "m_Field2";
            fRes &= t.GetField("m_Field1") != null;
            fRes &= t.GetField("m_Field2", BindingFlags.NonPublic | BindingFlags.Instance) != null;
            fRes &= t.GetConstructor(new Type[] { }) != null;
            
            Type[] ifaces = t.GetInterfaces();
            fRes &= ifaces.Length == 2;
            fRes &= ifaces[0].Name == "IInterface1";
            fRes &= ifaces[1].Name == "IInterface2";
            fRes &= t.IsSubclassOf(typeof(object));
            i++;

            // test Type members for a struct valuetype
            TestStruct str = new TestStruct();
            t = str.GetType();
            asm = t.Assembly;
            list.Add(asm);
            fRes &= ((Assembly)list[i]).GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= asm.GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
            fRes &= t.Name == "TestStruct";
            fRes &= t.FullName == "Microsoft.SPOT.Platform.Tests.SystemReflectionTypeTests+TestStruct";
            fRes &= t.BaseType == typeof(System.ValueType);
            fRes &= t.GetInterfaces().Length == 0;
            fRes &= t.GetElementType() == null;
            i++;

            // test Type members for an Assembly reflection type
            Assembly asmObj = typeof(TestClass).Assembly;
            t = asmObj.GetType();
            asm = t.Assembly;
            list.Add(asm);
            fRes &= ((Assembly)list[i]).GetName().Name == "mscorlib";
            fRes &= asm.GetName().Name == "mscorlib";
            fRes &= t.Name == "Assembly";
            fRes &= t.FullName == "System.Reflection.Assembly";
            fRes &= t.BaseType == typeof(Object);
            fRes &= t.GetInterfaces().Length == 0;
            fRes &= t.GetElementType() == null;

            mis = typeof(TestClass).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            t = mis.GetType();
            fRes &= t.Name == "RuntimeMethodInfo[]";
            fRes &= t.FullName == "System.Reflection.RuntimeMethodInfo[]";
            fRes &= t.BaseType == typeof(Array);
            fRes &= t.GetInterfaces().Length > 0;
            fRes &= t.GetElementType().Name == "RuntimeMethodInfo";

            // test Type members for a delegate
            Delegate del = new MyDelegate(MyDelegateImpl);
            t = del.GetType();
            fRes &= t.DeclaringType == null;
            fRes &= t.Name == "MyDelegate";
            fRes &= t.BaseType == typeof(MulticastDelegate);

            // test Type members for an enum
            TestEnum en = TestEnum.Item1;
            t = en.GetType();
            fRes &= t.DeclaringType == typeof(SystemReflectionTypeTests);
            fRes &= t.IsEnum;
            fRes &= !t.IsAbstract;
            fRes &= !t.IsClass;
            fRes &= !t.IsPublic;
            fRes &= t.IsValueType;

            return fRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
        public void SetCacherTest()
        {
            var cf = new MemoryCacherFactory(new StubCachePolicyFactory(), new ObjectCacheFactory());
            var ph = new PropertyHelper(cf);
            var tci = new TestClassImpl();
            var tc = new TestClass();

            ph.Set(tci.GetType().GetProperty("I"), tci, 1);
            ph.Set(tc.GetType().GetProperty("I"), tc, 2);

            Assert.AreEqual(tci.I, 1);
            Assert.AreEqual(tc.I, 2);
        }