public void RemoveRemovesItem() { var collection = new SimpleEventCollection { "A", "B", "C" }; Assert.IsTrue(collection.Remove("B")); Assert.IsFalse(collection.Remove("D")); Assert.AreEqual(2, collection.Count); Assert.IsTrue(collection.Contains("A")); Assert.IsFalse(collection.Contains("B")); Assert.IsTrue(collection.Contains("C")); Assert.AreEqual("AC", string.Join(string.Empty, collection)); }
public void RemoveWorksOnlyIfAllowed() { var collection = new SimpleEventCollection { "A", "B", "C" }; string result = string.Empty; collection.ItemRemoving += (sender, args) => { args.IsCanceled = args.Item == "B"; }; collection.ItemRemoved += (sender, args) => { result += args.Item; }; Assert.IsTrue(collection.Remove("A")); Assert.IsFalse(collection.Remove("B")); Assert.IsTrue(collection.Remove("C")); Assert.AreEqual(1, collection.Count); Assert.IsFalse(collection.Contains("A")); Assert.IsTrue(collection.Contains("B")); Assert.IsFalse(collection.Contains("C")); Assert.AreEqual("AC", result); }