コード例 #1
0
        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);
        }
コード例 #2
0
        public void SystemReflectionType_RuntimeType_Test1()
        {
            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);
            Assert.Equal(((Assembly)list[i]).GetName().Name, "NFUnitTest");
            Assert.Equal(asm.GetName().Name, "NFUnitTest");
            Assert.Equal(t.Name, "TestClass");
            Assert.Equal(t.FullName, "NFUnitTestSystemLib.UnitTestReflectionTypeTest+TestClass");
            Assert.IsType(t.BaseType, typeof(object));
            Assert.Null(t.GetElementType());

            MethodInfo[] mis = t.GetMethods();
            Assert.Equal(mis[0].Name, "Method1");
            mis = t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.Equal(mis[0].Name, "Method2");
            Assert.NotNull(t.GetMethod("Method1"));
            Assert.NotNull(t.GetMethod("Method2", BindingFlags.Instance | BindingFlags.NonPublic));

            FieldInfo[] fis = t.GetFields();
            Assert.Equal(fis[0].Name, "m_Field1");
            fis = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.Equal(fis[0].Name, "m_Field2");
            Assert.NotNull(t.GetField("m_Field1"));
            Assert.NotNull(t.GetField("m_Field2", BindingFlags.NonPublic | BindingFlags.Instance));
            Assert.NotNull(t.GetConstructor(new Type[] { }));

            Type[] ifaces = t.GetInterfaces();
            Assert.Equal(ifaces.Length, 2);
            Assert.Equal(ifaces[0].Name, "IInterface1");
            Assert.Equal(ifaces[1].Name, "IInterface2");
            Assert.True(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);
            Assert.Equal(((Assembly)list[i]).GetName().Name, "NFUnitTest");
            Assert.Equal(asm.GetName().Name, "NFUnitTest");
            Assert.Equal(t.Name, "TestStruct");
            Assert.Equal(t.FullName, "NFUnitTestSystemLib.UnitTestReflectionTypeTest+TestStruct");
            Assert.IsType(t.BaseType, typeof(ValueType));
            Assert.Equal(t.GetInterfaces().Length, 0);
            Assert.Null(t.GetElementType());
            i++;

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

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

            // test Type members for a delegate
            Delegate del = new MyDelegate(MyDelegateImpl);

            t = del.GetType();
            Assert.NotNull(t.DeclaringType);
            Assert.Equal(t.Name, "MyDelegate");
            Assert.IsType(t.BaseType, typeof(MulticastDelegate));

            // test Type members for an enum
            TestEnum en = TestEnum.Item1;

            t = en.GetType();
            Assert.IsType(t.DeclaringType, typeof(UnitTestReflectionTypeTest));
            Assert.True(t.IsEnum);
            Assert.False(t.IsAbstract);
            Assert.False(t.IsClass);
            Assert.False(t.IsPublic);
            Assert.True(t.IsValueType);
        }
コード例 #3
0
ファイル: ParseHelper.cs プロジェクト: vestild/nemerle
        /// <summary>
        /// Gets the code stream.
        /// </summary>
        /// <param name="test">The test.</param>
        /// <returns></returns>
        public static Stream GetCodeStream(TestEnum test)
        {
            string testName = test.ToString() + ".n";
            Stream codeStream = typeof (ParseHelper).Assembly.GetManifestResourceStream(test.GetType(), testName);

            Assert.IsNotNull(codeStream,
                String.Format(CultureInfo.CurrentCulture, Settings.Default.NotFoundCodeStream, testName));
            return codeStream;
        }
コード例 #4
0
ファイル: ParseHelper.cs プロジェクト: ugurak/nemerle
        /// <summary>
        /// Gets the code stream.
        /// </summary>
        /// <param name="test">The test.</param>
        /// <returns></returns>
        public static Stream GetCodeStream(TestEnum test)
        {
            string testName   = test.ToString() + ".n";
            Stream codeStream = typeof(ParseHelper).Assembly.GetManifestResourceStream(test.GetType(), testName);

            Assert.IsNotNull(codeStream,
                             String.Format(CultureInfo.CurrentCulture, Settings.Default.NotFoundCodeStream, testName));
            return(codeStream);
        }