public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Equals should return true when comparing with instance of same classes"); try { TestEmptyClass ec1 = new TestEmptyClass(); TestEmptyClass ec2 = new TestEmptyClass(); RuntimeTypeHandle handle1 = ec1.GetType().TypeHandle; RuntimeTypeHandle handle2 = ec2.GetType().TypeHandle; if (!handle1.Equals(handle2)) { TestLibrary.TestFramework.LogError("002.1", "Equals returns false when comparing with instance of same classe"); retVal = false; } TestStruct1 ts1 = new TestStruct1(); TestStruct1 ts2 = new TestStruct1(); handle1 = ts1.GetType().TypeHandle; handle2 = ts2.GetType().TypeHandle; if (!handle1.Equals(handle2)) { TestLibrary.TestFramework.LogError("002.2", "Equals returns false when comparing with instance of same structs"); retVal = false; } TestEnum1 te1 = TestEnum1.DEFAULT; TestEnum1 te2 = TestEnum1.DEFAULT; handle1 = te1.GetType().TypeHandle; handle2 = te2.GetType().TypeHandle; if (!handle1.Equals(handle2)) { TestLibrary.TestFramework.LogError("002.3", "Equals returns false when comparing with instance of same enums"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.4", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Equals should return false when comparing with instance of different classes"); try { TestEmptyClass classInstance1 = new TestEmptyClass(); TestClass classInstance2 = new TestClass(); RuntimeTypeHandle classInstanceHandle1 = classInstance1.GetType().TypeHandle; RuntimeTypeHandle classInstanceHandle2 = classInstance2.GetType().TypeHandle; if (classInstanceHandle1.Equals(classInstanceHandle2)) { TestLibrary.TestFramework.LogError("003.1", "Equals returns true when comparing with instance of different classe"); retVal = false; } TestStruct1 ts1 = new TestStruct1(); TestStruct2 ts2 = new TestStruct2(); RuntimeTypeHandle structHandle1 = ts1.GetType().TypeHandle; RuntimeTypeHandle structHandle2 = ts2.GetType().TypeHandle; if (structHandle1.Equals(structHandle2)) { TestLibrary.TestFramework.LogError("003.2", "Equals returns false when comparing with instance of different structs"); retVal = false; } TestEnum1 te1 = TestEnum1.DEFAULT; TestEnum2 te2 = TestEnum2.DEFAULT; RuntimeTypeHandle enumHandle1 = te1.GetType().TypeHandle; RuntimeTypeHandle enumHandle2 = te2.GetType().TypeHandle; if (enumHandle1.Equals(enumHandle2)) { TestLibrary.TestFramework.LogError("003.3", "Equals returns false when comparing with instance of different enums"); retVal = false; } if (classInstanceHandle1.Equals(structHandle1)) { TestLibrary.TestFramework.LogError("003.4", "Equals returns false when comparing a instance of struct with a instance of class"); retVal = false; } if (classInstanceHandle1.Equals(enumHandle1)) { TestLibrary.TestFramework.LogError("003.5", "Equals returns false when comparing a instance of enum with a instance of class"); retVal = false; } if (structHandle1.Equals(enumHandle1)) { TestLibrary.TestFramework.LogError("003.6", "Equals returns false when comparing a instance of struct with a instance of enum"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("003.7", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }