public void DefaultCollectionModificationRaisesChangeEvents()
        {
            var collection = new ItemsSourceCollection();

            // We want to test that the following methods raise the
            // PropertyChanged/CollectionChanged events.
            TestChangeEventsForAction(() => collection.Add(1));
            TestChangeEventsForAction(() =>
            {
                collection.Add(0);
                collection.Remove(0);
            });
            TestChangeEventsForAction(() =>
            {
                collection.Add(0);
                collection.RemoveAt(0);
            });
            TestChangeEventsForAction(() => collection.Clear());

            // Checks if the *Changed events are raised when executing changeAction().
            void TestChangeEventsForAction(Action changeAction)
            {
                Assert.PropertyChanged(
                    collection,
                    nameof(ItemsSourceCollection.Count),
                    changeAction);
                Assert.PropertyChanged(
                    collection,
                    "Items[]",
                    changeAction);
                AssertCollectionChanged(
                    collection,
                    changeAction);
            }
        }
        public void ThrowsWhenModifyingCollectionWithItemsSource()
        {
            var itemsSource = CreateIntItemsSource(5);
            var collection  = new ItemsSourceCollection();

            collection.ItemsSource = itemsSource;
            TestForMethod(() => collection.Add(0));
            TestForMethod(() => collection.Remove(0));
            TestForMethod(() => collection.RemoveAt(0));
            TestForMethod(() => collection.Clear());
            Assert.True(collection.Cast <int>().SequenceEqual(itemsSource));

            void TestForMethod(Action method)
            {
                var ex = Record.Exception(method);

                Assert.NotNull(ex);
                Assert.IsType <InvalidOperationException>(ex);
            }
        }