public void AddOnce_SignalWithNoTypeGivenSameCallbackMultipleTimes_ExpectsDelegateCalledOnlyOnce() { Signal signal = new Signal(); intToIncrement = 0; signal.AddOnce(SimpleSignalCallback); signal.AddOnce(SimpleSignalCallback); signal.Dispatch(); Assert.AreEqual(1, intToIncrement); }
public void AddOnce_SignalWithOneTypeGivenSameCallbackMultipleTimes_ExpectsDelegateCalledOnlyOnce() { Signal <int> signal = new Signal <int>(); testInt = 42; signal.AddOnce(OneArgSignalCallback); signal.AddOnce(OneArgSignalCallback); signal.Dispatch(testInt); Assert.AreEqual(testInt, testValue); }
public void TestRemoveAllRemovesOnce() { Signal signal = new Signal(); signal.AddOnce(NoArgSignalCallback); signal.AddOnce(NoArgSignalCallbackTwo); signal.RemoveAllListeners(); signal.Dispatch(); Assert.AreEqual(0, testValue); }
public void AddOnce_SignalWithFourTypesGivenSameCallbackMultipleTimes_ExpectsDelegateCalledOnlyOnce() { Signal <int, int, int, int> signal = new Signal <int, int, int, int>(); this.CreateFourInts(); signal.AddOnce(FourArgCallback); signal.AddOnce(FourArgCallback); signal.Dispatch(testInt, testIntTwo, testIntThree, testIntFour); int expected = this.GetFourIntExpected(); Assert.AreEqual(expected, this.testValue); }
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 }
public void TestOnce() { Signal <int> signal = new Signal <int>(); signal.AddOnce(OneArgSignalCallback); signal.Dispatch(testInt); Assert.AreEqual(testInt, testValue); signal.Dispatch(testInt); Assert.AreEqual(testInt, testValue); //should not fire a second time }
public void AddOnceTest() { var signal = new Signal(); var counter = 0; Slot listener1 = ((args) => { counter++; }); signal.AddOnce(listener1); // dispatch zwei signal.Dispatch(); signal.Dispatch(); Assert.AreEqual(1, counter, "The listener should only be called once"); }
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 }
public static void DispatchAndListen <A, B, C, D>(this Signal dispatchingSignal, Signal <A, B, C, D> listenOn, Action <A, B, C, D> callback) { listenOn.AddOnce(callback); dispatchingSignal.Dispatch(); }
public static void ListenAndStartWith <A, B, C, D>(this Signal <A, B, C, D> listeningSignal, Action startProcess, Action <A, B, C, D> callback) { listeningSignal.AddOnce(callback); startProcess.Invoke(); }