public void RemoveAddedEventHandler()
        {
            var             component       = new DescriptorTestComponent();
            Action          eventHandler    = () => Assert.True(false, "EventDescriptor failed to remove an event handler");
            EventDescriptor eventDescriptor = TypeDescriptor.CreateEvent(component.GetType(), nameof(component.ActionEvent), typeof(Action));

            eventDescriptor.AddEventHandler(component, eventHandler);
            eventDescriptor.RemoveEventHandler(component, eventHandler);

            // component.Event should now have no handler => raising it should throw a NullReferenceException
            Assert.Throws <NullReferenceException>(() => component.RaiseEvent());
        }
Example #2
0
        public void RemoveAddedEventHandler()
        {
            var component = new DescriptorTestComponent();
            Action eventHandler = () => Assert.True(false, "EventDescriptor failed to remove an event handler");
            EventDescriptor eventDescriptor = TypeDescriptor.CreateEvent(component.GetType(), nameof(component.ActionEvent), typeof(Action));

            eventDescriptor.AddEventHandler(component, eventHandler);
            eventDescriptor.RemoveEventHandler(component, eventHandler);

            // component.Event should now have no handler => raising it should throw a NullReferenceException
            Assert.Throws(typeof(NullReferenceException), () => component.RaiseEvent());
        }
        public void RaiseAddedEventHandler()
        {
            var             component             = new DescriptorTestComponent();
            var             eventHandlerWasCalled = false;
            Action          eventHandler          = () => eventHandlerWasCalled = true;
            var             eventInfo             = typeof(DescriptorTestComponent).GetEvent(nameof(DescriptorTestComponent.ActionEvent));
            EventDescriptor eventDescriptor       = TypeDescriptor.CreateEvent(component.GetType(), nameof(component.ActionEvent), typeof(Action));

            eventDescriptor.AddEventHandler(component, eventHandler);
            component.RaiseEvent();

            Assert.True(eventHandlerWasCalled);
        }
Example #4
0
        public void RaiseAddedEventHandler()
        {
            var component = new DescriptorTestComponent();
            var eventHandlerWasCalled = false;
            Action eventHandler = () => eventHandlerWasCalled = true;
            var eventInfo = typeof(DescriptorTestComponent).GetTypeInfo().GetEvent(nameof(DescriptorTestComponent.ActionEvent));
            EventDescriptor eventDescriptor = TypeDescriptor.CreateEvent(component.GetType(), nameof(component.ActionEvent), typeof(Action));

            eventDescriptor.AddEventHandler(component, eventHandler);
            component.RaiseEvent();

            Assert.True(eventHandlerWasCalled);
        }