public void TestRemoveAt() { var list = new List <string> { "aaa", "bbb", "ccc" }; var set = new ObservableSet <string>(list); Assert.Equal(set.Count, list.Count); bool propertyChangedInvoked = false; bool collectionChangedInvoked = false; set.PropertyChanged += (sender, e) => { Assert.Equal(nameof(ObservableSet <string> .Count), e.PropertyName); propertyChangedInvoked = true; }; set.CollectionChanged += (sender, e) => { Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action); Assert.Equal(1, e.OldStartingIndex); Assert.NotNull(e.OldItems); Assert.Equal(1, e.OldItems.Count); Assert.Equal("bbb", e.OldItems[0]); collectionChangedInvoked = true; }; set.RemoveAt(1); Assert.Equal(2, set.Count); Assert.Equal("aaa", set[0]); Assert.Equal("ccc", set[1]); Assert.True(propertyChangedInvoked); Assert.True(collectionChangedInvoked); }
public void TestRemoveAt() { var list = new List<string> { "aaa", "bbb", "ccc" }; var set = new ObservableSet<string>(list); Assert.AreEqual(set.Count, list.Count); bool propertyChangedInvoked = false; bool collectionChangedInvoked = false; set.PropertyChanged += (sender, e) => { Assert.AreEqual(e.PropertyName, nameof(ObservableSet<string>.Count)); propertyChangedInvoked = true; }; set.CollectionChanged += (sender, e) => { Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Remove); Assert.AreEqual(e.OldStartingIndex, 1); Assert.NotNull(e.OldItems); Assert.AreEqual(e.OldItems.Count, 1); Assert.AreEqual(e.OldItems[0], "bbb"); collectionChangedInvoked = true; }; set.RemoveAt(1); Assert.AreEqual(set.Count, 2); Assert.AreEqual(set[0], "aaa"); Assert.AreEqual(set[1], "ccc"); Assert.True(propertyChangedInvoked); Assert.True(collectionChangedInvoked); }