Beispiel #1
0
        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;
        }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
        public void TestEventKeepsCallCount()
        {
            TofuEvent evnt = new TofuEvent(EventKey.Test);

            Assert.AreEqual(0, evnt.CallCount);

            evnt.HasBeenCalled();

            Assert.AreEqual(1, evnt.CallCount);
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        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();
        }
Beispiel #10
0
        public void TestEventConstructor()
        {
            TofuEvent evnt = new TofuEvent(EventKey.Test);

            Assert.AreEqual(EventKey.Test, evnt.Key);
        }
Beispiel #11
0
 public void UnbindListener(TofuEvent evnt, Action <EventPayload> action, IEventContext evntContext)
 {
     evntContext.ContextRemoveEventListener(evnt, this);
     _boundListeners[evnt].Remove(action);
 }