Exemplo n.º 1
0
        public void AddTest()
        {
            var events = new BindableEvents(new Bindable <int>());

            BindableCallback listener1 = ((c, o) => { });
            BindableCallback listener2 = ((c, o) => { });

            // add two
            events.Add(listener1);
            events.Add(listener2);

            // get the listeners
            BindableCallback listeners = (BindableCallback)UnitTestUtil.GetProtected(events, "Listeners");

            Assert.AreEqual(listeners.GetInvocationList().Length, 2, "There should be two listeners by now");

            events.Remove(listener1); // remove the first one

            listeners = (BindableCallback)UnitTestUtil.GetProtected(events, "Listeners");
            Assert.AreEqual(listeners.GetInvocationList().Count(), 1, "There should only be one listener left");

            events.Remove(listener1); // try to remove it again

            listeners = (BindableCallback)UnitTestUtil.GetProtected(events, "Listeners");
            Assert.AreEqual(listeners.GetInvocationList().Count(), 1, "There should still be one listener left");

            events.Remove(listener2); // remove the other one

            listeners = (BindableCallback)UnitTestUtil.GetProtected(events, "Listeners");
            Assert.IsNull(listeners, "There should be no listener left");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add a listener.
 /// </summary>
 /// <param name="listener">The listener</param>
 public void Add(BindableCallback listener)
 {
     // prevent that the same listener is added multiple times
     if (Listeners == null || !Listeners.GetInvocationList().Contains(listener))
     {
         Listeners += listener;
     }
 }
Exemplo n.º 3
0
        public void AddingListenerMultipleTimesTest()
        {
            var events = new BindableEvents(new Bindable <int>());

            BindableCallback listener1 = ((c, o) => { });

            // add two
            events.Add(listener1);
            events.Add(listener1);

            // get the listeners
            BindableCallback listeners = (BindableCallback)UnitTestUtil.GetProtected(events, "Listeners");

            Assert.AreEqual(listeners.GetInvocationList().Length, 1, "There should only be listeners registered");
        }