Exemplo n.º 1
0
        public void DeadListenersRemovedRightAway()
        {
            var slot = new EventSlot();

            bool called = false;
            bool dead   = false;
            int  count  = 0;

            IEventListener listener = new DelegateEventListener(() => { if (count == 0)
                                                                        {
                                                                            dead = true;
                                                                        }
                                                                        else
                                                                        {
                                                                            called = true;
                                                                        } ++count; }, () => dead);

            slot.Register(listener);

            slot.Trigger();
            dead = false;

            slot.Trigger();

            Assert.That(!called);
        }
Exemplo n.º 2
0
        public void ExceptionsDuringTriggerDontEraseSlot()
        {
            var slot = new EventSlot();

            bool called = false;

            IEventListener listener2 = new DelegateEventListener(() => called = true);

            bool           dead     = false;
            IEventListener listener = new DelegateEventListener(() => { dead = true; throw new Exception(); }, () => dead);


            slot.Register(listener);

            slot.Register(listener2);

            try
            {
                slot.Trigger();
            }
            catch (Exception) {}

            slot.Trigger();

            Assert.That(called);
        }
Exemplo n.º 3
0
        public void DeadListenerNotCalled()
        {
            var slot = new EventSlot();

            bool called = false;

            IEventListener listener = new DelegateEventListener(() => called = true, () => true);

            slot.Register(listener);
            slot.Trigger();

            Assert.That(!called);
        }
Exemplo n.º 4
0
        public void CalledWithDelegateEventListener()
        {
            var slot = new EventSlot();

            bool called = false;

            IEventListener listener = new DelegateEventListener(() => called = true);

            slot.Register(listener);
            slot.Trigger();

            Assert.That(called);
        }