Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void AddedListenerIsCalled()
        {
            var wasCalled = false;
            var signal    = new Signal();

            signal.AddListener(() => wasCalled = true);
            signal.Call();

            Assert.True(wasCalled);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }