public void AliveItemsToList_ShouldReturnAllAliveItems() { var list = new object[] { new object(), new object(), new object() }; var wrc = new WeakReferenceCollection <object>(); var obj1 = new object(); wrc.Add(obj1); foreach (object obj in list) { wrc.Add(obj); } var obj2 = new object(); wrc.Add(obj2); Assert.AreEqual(list.Length + 2, wrc.AliveItemsToList().Count, "Should have same number of items!"); obj1 = obj2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); var aliveItems = wrc.AliveItemsToList(); Assert.AreEqual(list.Length, aliveItems.Count, "Should have 2 less items!"); Assert.AreEqual(list[0], aliveItems[0]); Assert.AreEqual(list[1], aliveItems[1]); Assert.AreEqual(list[2], aliveItems[2]); }
public void Remove_ObjectShouldGetRemoved() { var obj = new object(); var wrc = new WeakReferenceCollection <object>(); wrc.Add(obj); Assert.AreEqual(1, wrc.AliveItemsToList().Count, "Should have 1 item!"); wrc.Remove(obj); Assert.AreEqual(0, wrc.AliveItemsToList().Count, "Should have 0 item!"); }
public void AliveItemsToList_ShouldReturnAllItems() { var list = new object[] { new object(), new object(), new object() }; var wrc = new WeakReferenceCollection <object>(); foreach (object obj in list) { wrc.Add(obj); } Assert.AreEqual(list.Length, wrc.AliveItemsToList().Count, "Should have same number of items!"); }
public void AliveItemsToList_ShouldReturnEmpty() { var wrc = new WeakReferenceCollection <object>(); Assert.AreEqual(0, wrc.AliveItemsToList().Count, "Should have 0 items!"); }