Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
        }