public void ExpectContainsToReturnTrueOnlyIfFunctionWasAdded() { Action <float> func = dt => {}; var updateList = new UpdateList(); Assert.IsFalse(updateList.Contains(func)); updateList.Add(func); Assert.IsTrue(updateList.Contains(func)); }
public void ExpectContainsToReturnFalseAfterRemoveWasCalled() { Action <float> func = dt => { }; var updateList = new UpdateList(); updateList.Add(func); updateList.Remove(func); Assert.IsFalse(updateList.Contains(func)); }
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)); }
/// <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); } }
/// <summary> /// List内对象属性值变化后的处理 /// </summary> /// <param name="e"></param> private void ItemChanged(ListChangedEventArgs e) { if ("IsChecked".Equals(e.PropertyDescriptor.Name)) { return; } //*************************** //是否要过滤TBModel以外的属性 //*************************** if (!InsertList.Contains(this[e.NewIndex]) && !DeleteList.Contains(this[e.NewIndex]) && !UpdateList.Contains(this[e.NewIndex])) { UpdateList.Add(this[e.NewIndex]); } }
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)); }
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); }