Exemple #1
0
        public void TestPreviousKnownBreakingEdgecases()
        {
            var updateList = new UpdateList();

            // we have to create another ref to the functions so we can self remove within closures
            Action <float> func2 = null;
            Action <float> func0 = null;

            Action <float> update2 = dt =>
            {
                // Do nothing special
            };

            Action <float> update1 = dt =>
            {
                updateList.Remove(func2);
            };

            Action <float> update0 = dt =>
            {
                updateList.Remove(func0);
            };

            func2 = update2;
            func0 = update0;

            updateList.Add(update0);
            updateList.Add(update1);
            updateList.Add(update2);

            updateList.Update(0f);

            Assert.IsFalse(updateList.Contains(update0));
            Assert.IsTrue(updateList.Contains(update1));
            Assert.IsFalse(updateList.Contains(update2));

            // now dead test that index 2 is not marked as dead. by adding new updates, running them and checking they still exist
            updateList.Remove(update1);

            Action <float> update3Index0 = dt => { };
            Action <float> update4Index1 = dt => { };
            Action <float> update5Index2 = dt => { };


            updateList.Add(update3Index0);
            updateList.Add(update4Index1);
            updateList.Add(update5Index2);

            updateList.Update(0f);

            Assert.IsTrue(updateList.Contains(update3Index0));
            Assert.IsTrue(updateList.Contains(update4Index1));
            Assert.IsTrue(updateList.Contains(update5Index2));
        }
Exemple #2
0
        public void ExpectContainsToReturnFalseAfterRemoveWasCalled()
        {
            Action <float> func       = dt => { };
            var            updateList = new UpdateList();

            updateList.Add(func);
            updateList.Remove(func);
            Assert.IsFalse(updateList.Contains(func));
        }
Exemple #3
0
        public void ExpectRemoveToThrowIfFunctionWasNotFound()
        {
            Action <float> func       = dt => {};
            var            updateList = new UpdateList();

            Assert.Throws <Exception>(() =>
            {
                updateList.Remove(func);
            });
        }
Exemple #4
0
        /// <summary>
        /// Remove key from list of completed update tasks
        /// </summary>
        /// <param name="oldKey">Key to remove</param>
        /// <returns></returns>
        public async Task RemoveKeyAsync(string oldKey)
        {
            if (!(await GetKeyListAsync()).Contains(item: oldKey))
            {
                return;
            }

            UpdateList.Remove(item: UpdateList.FirstOrDefault(x => x.Key == oldKey));

            await SaveDataAsync();
        }
        /// <summary>
        /// List删除后的处理
        /// </summary>
        /// <param name="e"></param>
        private void ItemDeleted(ListChangedEventArgs e)
        {
            if (InsertList.Contains(_deletedItem))
            {
                InsertList.Remove(_deletedItem);
                return;
            }
            if (UpdateList.Contains(_deletedItem))
            {
                UpdateList.Remove(_deletedItem);
            }

            if (!DeleteList.Contains(_deletedItem))
            {
                DeleteList.Add(_deletedItem);
            }
        }
Exemple #6
0
        public void ExpectFunctionToNotBeCalledIfRemoveWasCalled()
        {
            var            wasCalled = false;
            Action <float> func      = dt =>
            {
                wasCalled = true;
            };

            var updateList = new UpdateList();

            updateList.Add(func);
            Assert.IsFalse(wasCalled);
            updateList.Remove(func);
            Assert.IsFalse(wasCalled);

            updateList.Update(0f);
            Assert.IsFalse(wasCalled);
        }
Exemple #7
0
        public void ExpectRemoveAndReAddWithinAnUpdateLoopToNotRemove()
        {
            var updateList = new UpdateList();

            Action <float> func2 = dt => { };
            Action <float> func1 = dt =>
            {
                updateList.Remove(func2);
                updateList.Add(func2);
            };

            updateList.Add(func1);
            updateList.Add(func2);

            updateList.Update(0f);

            Assert.IsTrue(updateList.Contains(func2));
        }
Exemple #8
0
        public void ExpectContainsToReturnFalseAfterRemoveWasCalledDuringFrame()
        {
            // we have to create another ref to the function so we can self remove within closure
            Action <float> funcRef = null;

            var updateList = new UpdateList();

            Action <float> func = dt =>
            {
                updateList.Remove(funcRef);

                Assert.IsFalse(updateList.Contains(funcRef));
            };

            funcRef = func;

            updateList.Add(funcRef);

            updateList.Update(0f);
        }
 public void RemoveTimer(Timer timer)
 {
     activeTimers.Remove(timer);
 }