public void ParamsAreSentToListener() { int[] passedParams = null; var signal = new Signal <int, int>(); signal.AddListener((p1, p2) => passedParams = new [] { p1, p2 }); signal.Call(13, 27); CollectionAssert.AreEqual(new [] { 13, 27 }, passedParams); }
public void AddedListenerIsCalled_Params() { var wasCalled = false; var signal = new Signal <int, int>(); signal.AddListener((ignore1, ignore2) => wasCalled = true); signal.Call(0, 0); Assert.True(wasCalled); }
public void AddedListenerIsCalled() { var wasCalled = false; var signal = new Signal(); signal.AddListener(() => wasCalled = true); signal.Call(); Assert.True(wasCalled); }
public void ParamsAreSentToListener() { int[] passedParams = null; var signal = new Signal <int>(); signal.AddListener(param => passedParams = new [] { param }); signal.Call(13); CollectionAssert.AreEqual(new [] { 13 }, passedParams); }
public void AllAddedListenersAreCalled_Params() { var wasCalled1 = false; var wasCalled2 = false; var signal = new Signal <int, int>(); signal.AddListener((ignore1, ignore2) => wasCalled1 = true); signal.AddListener((ignore1, ignore2) => wasCalled2 = true); signal.Call(0, 0); Assert.True(wasCalled1); Assert.True(wasCalled2); }
public void AllAddedListenersAreCalled() { var wasCalled1 = false; var wasCalled2 = false; var signal = new Signal(); signal.AddListener(() => wasCalled1 = true); signal.AddListener(() => wasCalled2 = true); signal.Call(); Assert.True(wasCalled1); Assert.True(wasCalled2); }
public void ClearRemovesAllListeners_Params() { var wasCalled = false; var signal = new Signal <int, int>(); signal.AddListener((ignore1, ignore2) => wasCalled = true); signal.AddListener((ignore1, ignore2) => wasCalled = true); signal.AddListener((ignore1, ignore2) => wasCalled = true); signal.AddListener((ignore1, ignore2) => wasCalled = true); signal.Clear(); signal.Call(0, 0); Assert.False(wasCalled); }
public void ClearRemovesAllListeners() { var wasCalled = false; var signal = new Signal(); signal.AddListener(() => wasCalled = true); signal.AddListener(() => wasCalled = true); signal.AddListener(() => wasCalled = true); signal.AddListener(() => wasCalled = true); signal.Clear(); signal.Call(); Assert.False(wasCalled); }
public void ListenersShouldBeRemovedByContext_Params() { var wasCalled = false; var wasFailed = false; var signal = new Signal <int, int>(); signal.AddListener((ignore1, ignore2) => wasCalled = true, "test1"); signal.AddListener((ignore1, ignore2) => wasFailed = true, "test2"); signal.AddListener((ignore1, ignore2) => wasCalled = true, "test1"); signal.AddListener((ignore1, ignore2) => wasFailed = true, "test2"); signal.RemoveListenerByContext("test2"); signal.Call(0, 0); Assert.True(wasCalled); Assert.False(wasFailed); }
public void ListenersShouldBeRemovedByContext() { var wasCalled = false; var wasFailed = false; var signal = new Signal(); signal.AddListener(() => wasCalled = true, "test1"); signal.AddListener(() => wasFailed = true, "test2"); signal.AddListener(() => wasCalled = true, "test1"); signal.AddListener(() => wasFailed = true, "test2"); signal.RemoveListenerByContext("test2"); signal.Call(); Assert.True(wasCalled); Assert.False(wasFailed); }
public void ListenersAreCalledInDescendingPriorityOrderInAscendingAgeOrder_Params() { var calls = new List <int>(); var signal = new Signal <int, int>(); signal.AddListener((ignore1, ignore2) => calls.Add(1), null, 10); signal.AddListener((ignore1, ignore2) => calls.Add(2), null, 8); signal.AddListener((ignore1, ignore2) => calls.Add(3), null, 9); signal.AddListener((ignore1, ignore2) => calls.Add(4), null, 10); signal.AddListener((ignore1, ignore2) => calls.Add(5), null, 7); signal.AddListener((ignore1, ignore2) => calls.Add(6), null, 11); signal.AddListener((ignore1, ignore2) => calls.Add(7), null, 8); signal.AddListener((ignore1, ignore2) => calls.Add(8), null, 9); signal.AddListener((ignore1, ignore2) => calls.Add(9), null, 9); signal.Call(0, 0); CollectionAssert.AreEqual(new[] { 6, 1, 4, 3, 8, 9, 2, 7, 5 }, calls); }