Example #1
0
 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 };
 }
Example #2
0
        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) };
        }
Example #3
0
        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);
        }