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 ClearRemoveAllItems() { var collection = new SimpleEventCollection { "A", "B", "C" }; collection.Clear(); Assert.AreEqual(0, collection.Count); Assert.IsFalse(collection.Contains("A")); Assert.IsFalse(collection.Contains("B")); Assert.IsFalse(collection.Contains("C")); Assert.AreEqual(string.Empty, string.Join(string.Empty, collection)); }
public void AddAddsItem() { var collection = new SimpleEventCollection(); collection.Add("A"); collection.Add("B"); collection.Add("C"); Assert.AreEqual(3, collection.Count); Assert.IsTrue(collection.Contains("A")); Assert.IsTrue(collection.Contains("B")); Assert.IsTrue(collection.Contains("C")); Assert.AreEqual("ABC", string.Join(string.Empty, collection)); }
public void AddWorksOnlyIfAllowed() { var collection = new SimpleEventCollection(); string result = string.Empty; collection.ItemAdding += (sender, args) => { args.IsCanceled = args.Item == "B"; }; collection.ItemAdded += (sender, args) => { result += args.Item; }; collection.Add("A"); collection.Add("B"); collection.Add("C"); Assert.AreEqual(2, collection.Count); Assert.IsTrue(collection.Contains("A")); Assert.IsFalse(collection.Contains("B")); Assert.IsTrue(collection.Contains("C")); Assert.AreEqual("AC", result); }
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); }