public void AddEventCancel() { var collection = new StatefulCollection <string>(new[] { "Hello", "World" }); collection.AddItem += (s, e) => { e.Cancel = e.Item.ToString() != "simplic"; Assert.IsNotNull(e.Item); }; collection.Add("test"); Assert.AreEqual(collection.Count, 2); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); collection.Add("simplic"); Assert.AreEqual(collection.Count, 2); Assert.AreEqual(collection.CountNewItems, 1); Assert.AreEqual(collection.CountRemovedItems, 0); collection.Commit(); Assert.AreEqual(collection.Count, 3); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); }
public void ClearEventCancel() { var cancel = true; var collection = new StatefulCollection <string>(new[] { "Hello", "World", "Simplic" }); collection.ClearCollection += (s, e) => { e.Cancel = cancel; }; collection.Clear(); Assert.AreEqual(collection.Count, 3); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); cancel = false; collection.Clear(); Assert.AreEqual(collection.Count, 0); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); // Test without event collection = new StatefulCollection <string>(new[] { "Hello", "World", "Simplic" }); collection.Clear(); Assert.AreEqual(collection.Count, 0); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); }
public void RemoveEventCancel() { var collection = new StatefulCollection <string>(new[] { "Hello", "World", "Simplic" }); collection.RemoveItem += (s, e) => { e.Cancel = e.Item.ToString() != "Simplic"; Assert.IsNotNull(e.Item); Assert.AreNotEqual(e.Item, "NotInList"); }; collection.Remove("NotInList"); Assert.AreEqual(collection.Count, 3); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); collection.Remove("Hello"); Assert.AreEqual(collection.Count, 3); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); collection.Remove("Simplic"); Assert.AreEqual(collection.Count, 2); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 1); collection.Commit(); Assert.AreEqual(collection.Count, 2); Assert.AreEqual(collection.CountNewItems, 0); Assert.AreEqual(collection.CountRemovedItems, 0); }