public static IEnumerable<object[]> AddEventHandler_TestData() { EI_Class tc1 = new EI_Class(); yield return new object[] { typeof(EI_Class).GetEvent("PublicEvent"), tc1, new VoidDelegate(tc1.PublicVoidMethod1), 1 }; yield return new object[] { typeof(EI_Class).GetEvent("PublicStaticEvent"), null, new VoidDelegate(tc1.ProtectedInternalVoidMethod), 2 }; yield return new object[] { typeof(EI_Class).GetEvent("PublicStaticEvent"), tc1, new VoidDelegate(tc1.PublicVoidMethod2), 3 }; }
public static IEnumerable <object[]> AddEventHandler_TestData() { EI_Class tc1 = new EI_Class(); yield return(new object[] { TypeExtensions.GetEvent(typeof(EI_Class), "PublicEvent"), tc1, new VoidDelegate(tc1.PublicVoidMethod1), 1 }); yield return(new object[] { TypeExtensions.GetEvent(typeof(EI_Class), "PublicStaticEvent"), null, new VoidDelegate(tc1.ProtectedInternalVoidMethod), 2 }); yield return(new object[] { TypeExtensions.GetEvent(typeof(EI_Class), "PublicStaticEvent"), tc1, new VoidDelegate(tc1.PublicVoidMethod2), 3 }); }
public static IEnumerable<object[]> AddEventHandler_Invalid_TestData() { // Null target for instance method EI_Class tc1 = new EI_Class(); yield return new object[] { typeof(EI_Class).GetEvent("PublicEvent"), null, new VoidDelegate(tc1.ProtectedInternalVoidMethod), typeof(TargetException) }; // Event not declared on target yield return new object[] { typeof(EI_Class).GetEvent("PublicEvent"), new DummyClass(), new VoidDelegate(tc1.ProtectedInternalVoidMethod), typeof(TargetException) }; // Event does not have a public add accessor yield return new object[] { typeof(EI_Class).GetEvent("PrivateEvent", BindingFlags.NonPublic | BindingFlags.Instance), new DummyClass(), new VoidDelegate(tc1.ProtectedInternalVoidMethod), typeof(InvalidOperationException) }; }
public static IEnumerable <object[]> AddEventHandler_Invalid_TestData() { // Null target for instance method EI_Class tc1 = new EI_Class(); yield return(new object[] { TypeExtensions.GetEvent(typeof(EI_Class), "PublicEvent"), null, new VoidDelegate(tc1.ProtectedInternalVoidMethod), typeof(TargetException) }); // Event not declared on target yield return(new object[] { TypeExtensions.GetEvent(typeof(EI_Class), "PublicEvent"), new DummyClass(), new VoidDelegate(tc1.ProtectedInternalVoidMethod), typeof(TargetException) }); // Event does not have a public add accessor yield return(new object[] { TypeExtensions.GetEvent(typeof(EI_Class), "PrivateEvent", BindingFlags.NonPublic | BindingFlags.Instance), new DummyClass(), new VoidDelegate(tc1.ProtectedInternalVoidMethod), typeof(InvalidOperationException) }); }
public void AddEventHandler_RemoveEventHandler(EventInfo eventInfo, EI_Class target, Delegate handler, int expectedStaticVariable) { // Add and make sure we bound the event. eventInfo.AddEventHandler(target, handler); target?.InvokeAllEvents(); EI_Class.InvokeStaticEvent(); Assert.Equal(expectedStaticVariable, EI_Class.AddEventHandler_RemoveEventHandler_Test_TrackingVariable); EI_Class.AddEventHandler_RemoveEventHandler_Test_TrackingVariable = 0; // Reset // Remove and make sure we unbound the event. eventInfo.RemoveEventHandler(target, handler); target?.InvokeAllEvents(); EI_Class.InvokeStaticEvent(); Assert.Equal(0, EI_Class.AddEventHandler_RemoveEventHandler_Test_TrackingVariable); }