Ejemplo n.º 1
0
        public void TestMultipleCallbacks()
        {
            Signal<int> signal = new Signal<int>();

            signal.AddListener(OneArgSignalCallback);
            signal.AddListener(OneArgSignalCallbackTwo);

            signal.Dispatch(testInt);

            Assert.AreEqual(testInt + 1, testValue);
        }
Ejemplo n.º 2
0
        public void TestFourArgSignal()
        {
            Signal<int, int, int, int> signal = new Signal<int, int, int, int>();

            int intendedResult = ((testInt + testIntTwo) * testIntThree) - testIntFour;
            signal.AddListener(FourArgSignalCallback);
            signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour);
            Assert.AreEqual(intendedResult, testValue);

            signal.RemoveListener(FourArgSignalCallback);
            signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour);
            Assert.AreEqual(intendedResult, testValue); //no-op due to remove

            intendedResult += testInt;
            intendedResult += testIntTwo;
            intendedResult *= testIntThree;
            intendedResult -= testIntFour;

            signal.AddOnce(FourArgSignalCallback);
            signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour);
            Assert.AreEqual(intendedResult, testValue);

            signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour);
            Assert.AreEqual(intendedResult, testValue); //Add once should result in no-op
        }
Ejemplo n.º 3
0
        public void TestNoArgSignal()
        {
            Signal signal = new Signal();

            signal.AddListener(NoArgSignalCallback);
            signal.Dispatch();
            Assert.AreEqual(1, testValue);
        }
Ejemplo n.º 4
0
        public void TestTwoArgSignal()
        {
            Signal<int, int> signal = new Signal<int, int>();

            signal.AddListener(TwoArgSignalCallback);
            signal.Dispatch(testInt, testIntTwo);
            Assert.AreEqual(testInt + testIntTwo, testValue);

            signal.RemoveListener(TwoArgSignalCallback);
            signal.Dispatch(testInt, testIntTwo);
            Assert.AreEqual(testInt + testIntTwo, testValue); //Removed listener should have no-op

            signal.AddOnce(TwoArgSignalCallback);
            signal.Dispatch(testInt, testIntTwo);
            Assert.AreEqual((testInt + testIntTwo) * 2, testValue);

            signal.Dispatch(testInt, testIntTwo);
            Assert.AreEqual((testInt + testIntTwo) * 2, testValue); //addonce should result in no-op

        }
Ejemplo n.º 5
0
        public void RemoveListener_NoType_ExpectsListenerRemoved()
        {
            Signal signal = new Signal();

            signal.AddListener(NoArgSignalCallback);

            signal.Dispatch();
            Assert.AreEqual(1, testValue);

            signal.RemoveListener(NoArgSignalCallback);
            signal.Dispatch();
            Assert.AreEqual(1, testValue);
        }
Ejemplo n.º 6
0
        public void TestRemoveListener()
        {
            Signal<int> signal = new Signal<int>();

            signal.AddListener(OneArgSignalCallback);

            signal.Dispatch(testInt);
            Assert.AreEqual(testInt, testValue);

            signal.RemoveListener(OneArgSignalCallback);
            signal.Dispatch(testInt);
            Assert.AreEqual(testInt, testValue);
        }
Ejemplo n.º 7
0
        public void AddListener_SignalWithFourTypesGivenSameCallbackMultipleTimes_ExpectsDelegateCalledOnlyOnce()
        {
            Signal<int, int, int, int> signal = new Signal<int, int, int, int>();
            this.CreateFourInts();
            signal.AddListener(FourArgCallback);
            signal.AddListener(FourArgCallback);

            signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour);

            int expected = this.GetFourIntExpected();
            Assert.AreEqual(expected, this.testValue);
        }
Ejemplo n.º 8
0
        public void AddListener_SignalWithOneTypeGivenSameCallbackMultipleTimes_ExpectsDelegateCalledOnlyOnce()
        {
            Signal<int> signal = new Signal<int>();
            testInt = 42;
            signal.AddListener(OneArgSignalCallback);
            signal.AddListener(OneArgSignalCallback);

            signal.Dispatch(testInt);

            Assert.AreEqual(testInt, testValue);
        }
Ejemplo n.º 9
0
        public void AddListener_SignalWithNoTypeGivenSameCallbackMultipleTimes_ExpectsDelegateCalledOnlyOnce()
        {
            Signal signal = new Signal();
            intToIncrement = 0;
            signal.AddListener(SimpleSignalCallback);
            signal.AddListener(SimpleSignalCallback);

            signal.Dispatch();

            Assert.AreEqual(1, intToIncrement);
        }
Ejemplo n.º 10
0
		public void TestRemoveAllListenersFour()
		{
			Signal<int, int, int, int> signal = new Signal<int, int, int, int>();

			signal.AddListener(FourArgSignalCallback);
			signal.AddListener(FourArgSignalCallbackTwo);

			signal.RemoveAllListeners();
			signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour);

			Assert.AreEqual(0, testValue);
		}
Ejemplo n.º 11
0
		public void TestRemoveAllListeners()
		{
			Signal signal = new Signal();

			signal.AddListener(NoArgSignalCallback);
			signal.AddListener(NoArgSignalCallbackTwo);

			signal.RemoveAllListeners();
			signal.Dispatch();

			Assert.AreEqual(0, testValue);
		}
Ejemplo n.º 12
0
		public void TestFactoryInjectionGivesUniqueInstances()
		{
			injectionBinder.Bind<ISimpleInterface> ().To<SimpleInterfaceImplementer> ();

			//This signal we dispatch
			Signal<Signal<SimpleInterfaceImplementer>> senderSignal = new Signal<Signal<SimpleInterfaceImplementer>> ();
			//This one is payload
			Signal<SimpleInterfaceImplementer> payloadSignal = new Signal<SimpleInterfaceImplementer> ();

			commandBinder.Bind (senderSignal).To<CommandWithInjectionAndSignal> ().Pooled();

			payloadSignal.AddListener (cb);

			//Dispatch the senderSignal twice, each time carrying the payloadSignal
			senderSignal.Dispatch(payloadSignal);
			senderSignal.Dispatch(payloadSignal);

			Assert.AreEqual (2, instanceList.Count);
			Assert.AreNotSame (instanceList [0], instanceList [1]);

		}
Ejemplo n.º 13
0
 virtual public void AddListener(Action callback)
 {
     specificSignal.AddListener(callback);
 }
Ejemplo n.º 14
0
 protected void RegisterListener <T, U, V, W>(Signal <T, U, V, W> signal, Action <T, U, V, W> callback)
 {
     SignalBindings.Add(signal.AddListener(callback));
 }
Ejemplo n.º 15
0
 protected void RegisterListener(Signal signal, Action callback)
 {
     SignalBindings.Add(signal.AddListener(callback));
 }