// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: Remove a function which is in the InvocationList and not only one method"); try { DelegateRemove delctor = new DelegateRemove(); TestClass tcInstance = new TestClass(); booldelegate bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool); booldelegate bWorking_Bool = new booldelegate(tcInstance.Working_Bool); booldelegate bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool); delctor.starkWork += bStartWork_Bool; delctor.starkWork += bStartWork_Bool; delctor.starkWork += bWorking_Bool; delctor.starkWork += bCompleted_Bool; delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(tcInstance.StartWork_Bool)); Delegate[] invocationList = delctor.starkWork.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("009", "remove failure: " + invocationList.Length); retVal = false; } if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool)) { TestLibrary.TestFramework.LogError("010", " remove failure "); retVal = false; } delctor.starkWork(); } catch (Exception e) { TestLibrary.TestFramework.LogError("011", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Remove a function which is not in the InvocationList"); try { DelegateRemove delctor = new DelegateRemove(); booldelegate bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool); booldelegate bWorking_Bool = new booldelegate(new TestClass().Working_Bool); booldelegate bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool); delctor.starkWork += bStartWork_Bool; delctor.starkWork += null; delctor.starkWork += bWorking_Bool; delctor.starkWork += bCompleted_Bool; delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(new TestClass().Completed_Bool)); Delegate[] invocationList = delctor.starkWork.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("006", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length); retVal = false; } if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool)) { TestLibrary.TestFramework.LogError("007", " remove failure "); retVal = false; } delctor.starkWork(); } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); retVal = false; } return(retVal); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Remove a function which is in the InvocationList"); try { DelegateRemove delctor = new DelegateRemove(); TestClass tcInstance = new TestClass(); booldelegate bStartWork_Bool = new booldelegate(tcInstance.StartWork_Bool); booldelegate bWorking_Bool = new booldelegate(tcInstance.Working_Bool); booldelegate bCompleted_Bool = new booldelegate(tcInstance.Completed_Bool); delctor.starkWork += bStartWork_Bool; delctor.starkWork += bWorking_Bool; delctor.starkWork += bCompleted_Bool; delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(tcInstance.Working_Bool)); Delegate[] invocationList = delctor.starkWork.GetInvocationList(); if (invocationList.Length != 2) { TestLibrary.TestFramework.LogError("003", "remove failure or remove method is not in the InvocationList"); retVal = false; } if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) || !delctor.starkWork.GetInvocationList()[1].Equals(bCompleted_Bool)) { TestLibrary.TestFramework.LogError("004", " remove failure "); retVal = false; } delctor.starkWork(); } catch (Exception e) { TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest5: Remove a function which is in the InvocationList and not only one method ,method is static method"); try { DelegateRemove delctor = new DelegateRemove(); booldelegate bStartWork_Bool = new booldelegate(TestClass1.StartWork_Bool); booldelegate bWorking_Bool = new booldelegate(TestClass1.Working_Bool); booldelegate bCompleted_Bool = new booldelegate(TestClass1.Completed_Bool); delctor.starkWork += bStartWork_Bool; delctor.starkWork += bStartWork_Bool; delctor.starkWork += bWorking_Bool; delctor.starkWork += bCompleted_Bool; delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(TestClass1.StartWork_Bool)); Delegate[] invocationList = delctor.starkWork.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("012", "remove failure: " + invocationList.Length); retVal = false; } if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool)) { TestLibrary.TestFramework.LogError("013", " remove failure "); retVal = false; } delctor.starkWork(); } catch (Exception e) { TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Remove a function which is not in the InvocationList"); try { DelegateRemove delctor = new DelegateRemove(); booldelegate bStartWork_Bool = new booldelegate(new TestClass().StartWork_Bool); booldelegate bWorking_Bool = new booldelegate(new TestClass().Working_Bool); booldelegate bCompleted_Bool = new booldelegate(new TestClass().Completed_Bool); delctor.starkWork += bStartWork_Bool; delctor.starkWork += null; delctor.starkWork += bWorking_Bool; delctor.starkWork += bCompleted_Bool; delctor.starkWork = (booldelegate)Delegate.Remove(delctor.starkWork, new booldelegate(new TestClass().Completed_Bool)); Delegate[] invocationList = delctor.starkWork.GetInvocationList(); if (invocationList.Length != 3) { TestLibrary.TestFramework.LogError("006", "Call GetInvocationList against a delegate with one function returns wrong result: " + invocationList.Length); retVal = false; } if (!delctor.starkWork.GetInvocationList()[0].Equals(bStartWork_Bool) || !delctor.starkWork.GetInvocationList()[1].Equals(bWorking_Bool) || !delctor.starkWork.GetInvocationList()[2].Equals(bCompleted_Bool)) { TestLibrary.TestFramework.LogError("007", " remove failure "); retVal = false; } delctor.starkWork(); } catch (Exception e) { TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e); retVal = false; } return retVal; }