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); }
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)); }
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); }
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); }
public void NotCalledIfNotTrigger() { var slot = new EventSlot(); bool called = false; slot.Register(() => called = true); Assert.That(!called); }
public void CalledWithDelegateEventListener() { var slot = new EventSlot(); bool called = false; IEventListener listener = new DelegateEventListener(() => called = true); slot.Register(listener); slot.Trigger(); Assert.That(called); }
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); }
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); }
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); }
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); }
public void RegisterAndStart(IEventTrigger <bool> evnt) { _changeStateEvent.Register(evnt); evnt.Trigger(Free); }
public FlagSemaphore(Action <string, bool> changeAct) { _changeStateEvent.Register(changeAct); }