public void ReceiveEvent(TofuEvent evnt, EventPayload payload) { if (_boundListeners == null) { return; } if (!_boundListeners.ContainsKey(evnt)) { Debug.Log("Expected event " + evnt + " but found no action bound"); } foreach (Action <EventPayload> action in _boundListeners[evnt]) { action.Invoke(payload); } _listenersToUnbind = new Dictionary <TofuEvent, Action <EventPayload> >(); foreach (KeyValuePair <TofuEvent, Action <EventPayload> > kvp in _listenersToUnbind) { UnbindListener(kvp.Key, kvp.Value, EventContext); } _listenersToUnbind = null; }
public void UnbindListener(TofuEvent evnt, Action <EventPayload> action, IEventContext evntContext) { evntContext.ContextRemoveEventListener(evnt, this); if (action != null && _boundListeners != null && _boundListeners.ContainsKey(evnt) && _boundListeners[evnt].Contains(action)) { _boundListeners[evnt].Remove(action); } }
public void TestEventKeepsCallCount() { TofuEvent evnt = new TofuEvent(EventKey.Test); Assert.AreEqual(0, evnt.CallCount); evnt.HasBeenCalled(); Assert.AreEqual(1, evnt.CallCount); }
public void TestTwoEventsEqualHashWithEqualNames() { TofuEvent evnt1 = new TofuEvent(EventKey.Test); TofuEvent evnt2 = new TofuEvent(EventKey.Test); TofuEvent evnt3 = new TofuEvent(EventKey.Test2); evnt2.HasBeenCalled(); Assert.AreEqual(evnt1.GetHashCode(), evnt2.GetHashCode()); Assert.AreNotEqual(evnt3.GetHashCode(), evnt1.GetHashCode()); }
public void TestTwoEventsAreEqualWithEqualNames() { TofuEvent evnt1 = new TofuEvent(EventKey.Test); TofuEvent evnt2 = new TofuEvent(EventKey.Test); TofuEvent evnt3 = new TofuEvent(EventKey.Test2); evnt2.HasBeenCalled(); Assert.AreEqual(evnt1, evnt2); Assert.AreNotEqual(evnt3, evnt1); }
public void UnbindListener(TofuEvent evnt, Action <EventPayload> action, IEventContext evntContext) { evntContext.ContextRemoveEventListener(evnt, this); if (_listenersToUnbind == null) { _listenersToUnbind = new Dictionary <TofuEvent, Action <EventPayload> >(); } if (!_listenersToUnbind.ContainsKey(evnt)) { _listenersToUnbind.Add(evnt, action); } }
public void BindListener(TofuEvent evnt, Action <EventPayload> action, IEventContext evntContext) { if (_boundListeners == null) { _boundListeners = new Dictionary <TofuEvent, List <Action <EventPayload> > >(); } if (!_boundListeners.ContainsKey(evnt)) { _boundListeners.Add(evnt, new List <Action <EventPayload> >()); } evntContext.ContextBindEventListener(evnt, this); _boundListeners[evnt].Add(action); }
public void ReceiveEvent(TofuEvent evnt, EventPayload payload) { FlushListeners(); if (_boundListeners == null) { return; } if (!_boundListeners.ContainsKey(evnt)) { Debug.Log("Expected event " + evnt + " but found no action bound"); } foreach (Action <EventPayload> action in _boundListeners[evnt]) { action.Invoke(payload); } FlushListeners(); }
public void SetUp() { //Prepare Bindings _subServiceContext = Substitute.For <IServiceContext>(); _subEventContext = Substitute.For <IEventContext>(); _subServiceContext.Has("IEventContext").Returns(true); _subServiceContext.Fetch("IEventContext").Returns(_subEventContext); //Prepare Events TofuEvent _frameUpdateEvent = new TofuEvent("FrameUpdate"); _subEventContext.GetEvent(EventKey.FrameUpdate).Returns(_frameUpdateEvent); //Prepare Object Under Test _glopContainer = new GlopContainer <Glop>(); _glopContainer.BindServiceContext(_subServiceContext); _glopContainer.ResolveServiceBindings(); _glopContainer.Build(); _glopContainer.Initialize(); }
public void TestEventConstructor() { TofuEvent evnt = new TofuEvent(EventKey.Test); Assert.AreEqual(EventKey.Test, evnt.Key); }
public void UnbindListener(TofuEvent evnt, Action <EventPayload> action, IEventContext evntContext) { evntContext.ContextRemoveEventListener(evnt, this); _boundListeners[evnt].Remove(action); }