public void ValidateExceptions() { Assert.Catch(typeof(TypeNotEventException), () => { EventManager.Instance.RegisterListener(typeof(Generic1), new Listener1()); }); Assert.Catch(typeof(TypeNotEventException), () => { EventManager.Instance.UnregisterListener(typeof(Generic1), new Listener1()); }); Assert.DoesNotThrow(() => { EventManager.Instance.TriggerEvent(new Event1()); }); Assert.DoesNotThrow(() => { EventManager.Instance.QueueEvent(new Event1()); }); Listener1 listener = new Listener1(); Assert.DoesNotThrow(() => { EventManager.Instance.RegisterListener(typeof(Event1), listener); }); Assert.DoesNotThrow(() => { EventManager.Instance.UnregisterListener(typeof(Event1), listener); }); EventManager.Instance.RegisterListener(typeof(Event1), listener); Assert.Throws(typeof(ListenerAlreadyExistsException), () => { EventManager.Instance.RegisterListener(typeof(Event1), listener); }); }
public void TriggerEvent() { Listener1 listener1 = new Listener1(); Listener2 listener2 = new Listener2(); EventManager.Instance.RegisterListener <Event1>(listener1); Assert.False(EventManager.Instance.TriggerEvent(new Event1())); EventManager.Instance.RegisterListener <Event1>(listener2); Assert.True(EventManager.Instance.TriggerEvent(new Event1())); EventManager.Instance.UnregisterListener <Event1>(listener2); Assert.False(EventManager.Instance.TriggerEvent(new Event1())); EventManager.Instance.RegisterListener <Event1>(listener2); EventManager.Instance.UnregisterListener(listener2); Assert.False(EventManager.Instance.TriggerEvent(new Event1())); Assert.That(() => { bool eventPropogated = false; PassListener listener = new PassListener((bool pass) => { eventPropogated = pass; }); EventManager.Instance.RegisterListener <Event1>(listener); EventManager.Instance.TriggerEvent(new Event1()); EventManager.Instance.UnregisterListener(listener); return(eventPropogated); }); }