Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void EventCallOrder()
        {
            var        slot = new EventSlot();
            List <int> ints = new List <int>();

            slot.Register(() => ints.Add(0));
            slot.Register(() => ints.Add(1));
            slot.Trigger();

            Assert.That(ints[0].Equals(0) && ints[1].Equals(1));
        }
Ejemplo n.º 3
0
        public void ListenerAddedDuringTriggerNotCalled()
        {
            var slot = new EventSlot();

            bool called = false;

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

            IEventListener listener = new DelegateEventListener(() => slot.Register(listener2));

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

            Assert.That(!called);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void NotCalledIfNotTrigger()
        {
            var  slot   = new EventSlot();
            bool called = false;

            slot.Register(() => called = true);

            Assert.That(!called);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void Once()
        {
            var slot = new EventSlot();

            int count = 0;

            IEventListener listener = DelegateEventListeners.Once(() => { ++count; });

            slot.Register(listener);

            slot.Trigger();
            slot.Trigger();

            Assert.AreEqual(1, count);
        }
Ejemplo n.º 8
0
        public void DeadListenerRemoved()
        {
            var slot = new EventSlot();

            bool called = false;
            bool dead   = true;

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

            slot.Register(listener);
            slot.Trigger();
            dead = false;
            slot.Trigger();

            Assert.That(!called);
        }
Ejemplo n.º 9
0
        public void LifeTimeEventListenerDontHoldGarbage()
        {
            var        slot = new EventSlot();
            List <int> list = new List <int>();

            {
                TestGarbage garbage  = new TestGarbage(list);
                var         listener = DelegateEventListeners.LifeTime((t) => t.Callback(), garbage);
                slot.Register(listener);
            }

            GC.Collect();

            slot.Trigger();

            Assert.AreEqual(0, list.Count);
        }
Ejemplo n.º 10
0
        public void LifeTimeEventListenerStillAlive()
        {
            var        slot = new EventSlot();
            List <int> list = new List <int>();


            TestGarbage garbage = new TestGarbage(list);

            var listener = DelegateEventListeners.LifeTime((t) => t.Callback(), garbage);

            slot.Register(listener);


            GC.Collect();

            slot.Trigger();
            garbage.Nothing = 2;
            Assert.AreEqual(1, list.Count);
        }
Ejemplo n.º 11
0
 public void RegisterAndStart(IEventTrigger <bool> evnt)
 {
     _changeStateEvent.Register(evnt); evnt.Trigger(Free);
 }
Ejemplo n.º 12
0
 public FlagSemaphore(Action <string, bool> changeAct)
 {
     _changeStateEvent.Register(changeAct);
 }