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 CanAddItemsNormally() { var collection = new ItemsSourceCollection(); int itemToAdd = 1; collection.Add(itemToAdd); Assert.Contains(itemToAdd, collection); }
public void IndexAccessorWorksWithDefaultCollection() { var collection = new ItemsSourceCollection(); int itemToAdd = 1; collection.Add(0); // Placeholder, so that the index exists. collection[0] = itemToAdd; Assert.Equal(itemToAdd, collection[0]); }
public void GetEnumeratorWorksWithDefaultCollection() { var collection = new ItemsSourceCollection(); var items = new int[] { 1, 2, 3, 4, 5 }; IEnumerator collectionEnumerator; IEnumerator itemsEnumerator; foreach (var item in items) { collection.Add(item); } collectionEnumerator = collection.GetEnumerator(); itemsEnumerator = items.GetEnumerator(); TestEnumeratorEquality(collectionEnumerator, itemsEnumerator); }
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); } }