Example #1
0
        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));
        }
Example #2
0
        public void SuccessfulClearWorks()
        {
            var collection = new SimpleEventCollection {
                "A", "B", "C"
            };
            string result = string.Empty;

            collection.ItemRemoving += (sender, args) => { };
            collection.ItemRemoved  += (sender, args) => { result += args.Item; };

            collection.Clear();

            Assert.AreEqual(0, collection.Count);
            Assert.AreEqual("ABC", result);
        }
Example #3
0
        public void ForbiddenClearFails()
        {
            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; };

            var error = Assert.Throws <ItemsCantBeRemovedException <string> >(() => collection.Clear());

            Assert.AreEqual(3, collection.Count);
            Assert.IsNullOrEmpty(result);
            Assert.AreEqual("B", error.Items.Single());
        }