public void MyTest() { var actual = new List <Tuple <object, Type> >(); var expected = new List <Tuple <object, Type> >(); var o1 = new TestObject1(); actual.Add(new Tuple <object, Type>(o1, o1.GetType())); expected.Add(new Tuple <object, Type>(o1, o1.GetType())); Reflection.GetTypes(actual); Assert.AreEqual(expected, actual); }
public MFTestResults SystemType4_DeclaringType_Test() { /// <summary> /// 1. Tests the BaseType DeclaringType for system and user defined types /// </summary> /// bool testResult = true; try { Log.Comment("This tests the DeclaringType property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.FullName); testResult &= (myType1.DeclaringType == null); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); Log.Comment("The full name is " + myType2.FullName); Type myType3 = this.GetType(); testResult &= (myType2.DeclaringType == myType3); } catch (Exception e) { Log.Comment("Typeless " + e.Message); testResult = false; } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults SystemType2_Assembly_Test() { /// <summary> /// 1. Tests the Assembly property for system and user defined types /// Fails if exception thrown /// </summary> /// bool testResult = true; try { Log.Comment("This tests the Assembly property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.Assembly.FullName); testResult &= (myType1.Assembly.FullName == "mscorlib, Version=" + myType1.Assembly.GetName().Version.ToString()); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); Log.Comment("The full name is " + myType2.Assembly.FullName); testResult &= (myType2.Assembly.FullName == "Microsoft.SPOT.Platform.Tests.Systemlib2, Version=" + myType2.Assembly.GetName().Version.ToString()); } catch (Exception e) { Log.Comment("Typeless " + e.Message); testResult = false; } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults SystemType1_GetType_Test() { /// <summary> /// 1. Tests the GetType(String) method /// 2. Tests the GetType() method /// </summary> /// bool testResult = true; try { Int32 testInt32 = 0; Assembly Int32Assm = Assembly.Load("mscorlib"); Log.Comment("This tests the Assembly.GetType(String) by passing \"Namespace.Class\""); Type myType0 = Int32Assm.GetType("System.Int32"); Log.Comment("The full name is " + myType0.FullName); testResult &= (myType0 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class\""); Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.FullName); testResult &= (myType1 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly\""); Type myType2 = Type.GetType("System.Int32, mscorlib"); Log.Comment("The full name is " + myType2.FullName); testResult &= (myType2 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly, Version=\"a.b.c.d\"\""); string typeName3 = "System.Int32, mscorlib, Version=" + Int32Assm.GetName().Version.ToString(); Type myType3 = Type.GetType(typeName3); Log.Comment("The full name is " + myType3.FullName); testResult &= (myType3 == testInt32.GetType()); Log.Comment("This tests the Type.GetType() method for nested classes"); TestObject1 testTestObject1 = new TestObject1(); Type myType4 = testTestObject1.GetType(); Log.Comment("The full name is " + myType4.FullName); testResult &= (myType4 == Type.GetType("Microsoft.SPOT.Platform.Tests.SystemTypeTests+TestObject1")); Log.Comment("Since NoneSuch does not exist in this assembly, "); Log.Comment("GetType throws a TypeLoadException."); Type myType5 = Type.GetType("NoneSuch"); Log.Comment("The full name is " + myType5.FullName); } catch (Exception e) { Log.Comment("Typeless " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public void SystemType1_GetTypeNew_Test() { Int32 testInt32 = 0; Assembly Int32Assm = Assembly.Load("mscorlib"); OutputHelper.WriteLine("This tests the Assembly.GetType(String) by passing \"Namespace.Class\""); Type myType0 = Int32Assm.GetType("System.Int32"); OutputHelper.WriteLine("The full name is " + myType0.FullName); Assert.IsType(myType0, testInt32.GetType()); OutputHelper.WriteLine("This tests the Type.GetType(String) by passing \"Namespace.Class\""); Type myType1 = Type.GetType("System.Int32"); OutputHelper.WriteLine("The full name is " + myType1.FullName); Assert.IsType(myType1, testInt32.GetType()); OutputHelper.WriteLine("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly\""); Type myType2 = Type.GetType("System.Int32, mscorlib"); OutputHelper.WriteLine("The full name is " + myType2.FullName); Assert.IsType(myType2, testInt32.GetType()); OutputHelper.WriteLine("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly, Version=\"a.b.c.d\"\""); string typeName3 = "System.Int32, mscorlib, Version=" + Int32Assm.GetName().Version.ToString(); Type myType3 = Type.GetType(typeName3); OutputHelper.WriteLine("The full name is " + myType3.FullName); Assert.IsType(myType3, testInt32.GetType()); OutputHelper.WriteLine("This tests the Type.GetType() method for nested classes"); TestObject1 testTestObject1 = new TestObject1(); Type myType4 = testTestObject1.GetType(); OutputHelper.WriteLine("The full name is " + myType4.FullName); Assert.IsType(myType4, Type.GetType("NFUnitTestSystemLib.UnitTestTypeTests+TestObject1")); OutputHelper.WriteLine("Since NoneSuch does not exist in this assembly, "); OutputHelper.WriteLine("GetType throws a TypeLoadException."); Assert.Throws(typeof(NullReferenceException), () => { Type myType5 = Type.GetType("NoneSuch"); OutputHelper.WriteLine("The full name is " + myType5.FullName); }); }
public void SystemType3_BaseType_Test() { OutputHelper.WriteLine("This tests the BaseType() method"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); OutputHelper.WriteLine("The full name is " + myType1.FullName); Assert.IsType(myType1.BaseType, Type.GetType("System.ValueType")); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); OutputHelper.WriteLine("The full name is " + myType2.FullName); Assert.IsType(myType2.BaseType, Type.GetType("System.Object")); }
public void SystemType2_Assembly_Test() { OutputHelper.WriteLine("This tests the Assembly property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); OutputHelper.WriteLine("The full name is " + myType1.Assembly.FullName); Assert.Equal(myType1.Assembly.FullName, "mscorlib, Version=" + myType1.Assembly.GetName().Version.ToString()); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); OutputHelper.WriteLine("The full name is " + myType2.Assembly.FullName); Assert.Equal(myType2.Assembly.FullName, "NFUnitTest, Version=" + myType2.Assembly.GetName().Version.ToString()); }
public MFTestResults SystemType1_GetType_Test() { /// <summary> /// 1. Tests the GetType(String) method /// 2. Tests the GetType() method /// </summary> /// bool testResult = true; try { Int32 testInt32 = 0; Assembly Int32Assm = Assembly.Load("mscorlib"); Log.Comment("This tests the Assembly.GetType(String) by passing \"Namespace.Class\""); Type myType0 = Int32Assm.GetType("System.Int32"); Log.Comment("The full name is " + myType0.FullName); testResult &= (myType0 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class\""); Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.FullName); testResult &= (myType1 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly\""); Type myType2 = Type.GetType("System.Int32, mscorlib"); Log.Comment("The full name is " + myType2.FullName); testResult &= (myType2 == testInt32.GetType()); Log.Comment("This tests the Type.GetType(String) by passing \"Namespace.Class, assembly, Version=\"a.b.c.d\"\""); string typeName3 = "System.Int32, mscorlib, Version=" + Int32Assm.GetName().Version.ToString(); Type myType3 = Type.GetType(typeName3); Log.Comment("The full name is " + myType3.FullName); testResult &= (myType3 == testInt32.GetType()); Log.Comment("This tests the Type.GetType() method for nested classes"); TestObject1 testTestObject1 = new TestObject1(); Type myType4 = testTestObject1.GetType(); Log.Comment("The full name is " + myType4.FullName); testResult &= (myType4 == Type.GetType("Microsoft.SPOT.Platform.Tests.SystemTypeTests+TestObject1")); Log.Comment("Since NoneSuch does not exist in this assembly, "); Log.Comment("GetType throws a TypeLoadException."); Type myType5 = Type.GetType("NoneSuch"); Log.Comment("The full name is " + myType5.FullName); } catch (Exception e) { Log.Comment("Typeless " + e.Message); } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults SystemType4_DeclaringType_Test() { /// <summary> /// 1. Tests the BaseType DeclaringType for system and user defined types /// </summary> /// bool testResult = true; try { Log.Comment("This tests the DeclaringType property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.FullName); testResult &= (myType1.DeclaringType == null); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); Log.Comment("The full name is " + myType2.FullName); Type myType3 = this.GetType(); testResult &= (myType2.DeclaringType == myType3); } catch (Exception e) { Log.Comment("Typeless " + e.Message); testResult = false; } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults SystemType2_Assembly_Test() { /// <summary> /// 1. Tests the Assembly property for system and user defined types /// Fails if exception thrown /// </summary> /// bool testResult = true; try { Log.Comment("This tests the Assembly property"); //Assigned and manipulated to avoid compiler warning Int32 testInt32 = -1; testInt32++; Type myType1 = Type.GetType("System.Int32"); Log.Comment("The full name is " + myType1.Assembly.FullName); testResult &= (myType1.Assembly.FullName == "mscorlib, Version=" + myType1.Assembly.GetName().Version.ToString()); TestObject1 testTestObject1 = new TestObject1(); Type myType2 = testTestObject1.GetType(); Log.Comment("The full name is " + myType2.Assembly.FullName); testResult &= (myType2.Assembly.FullName == "Microsoft.SPOT.Platform.Tests.Systemlib2, Version=" + myType2.Assembly.GetName().Version.ToString()); } catch (Exception e) { Log.Comment("Typeless " + e.Message); testResult = false; } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }