public void Set() { ObservableList <char> collection = new ObservableList <char>(); bool propertyChanged = false; List <string> changedProps = new List <string>(); NotifyCollectionChangedEventArgs args = null; collection.Add('A'); collection.Add('B'); collection.Add('C'); ((INotifyPropertyChanged)collection).PropertyChanged += (sender, e) => { propertyChanged = true; changedProps.Add(e.PropertyName); }; collection.CollectionChanged += (sender, e) => { args = e; }; collection[2] = 'I'; Assert.IsTrue(propertyChanged, "SET_1"); Assert.IsTrue(changedProps.Contains("Item[]"), "SET_2"); CollectionChangedEventValidators.ValidateReplaceOperation(args, new char[] { 'C' }, new char[] { 'I' }, 2, "SET_3"); }
public void Reentrant() { ObservableList <char> collection = new ObservableList <char>(); bool propertyChanged = false; List <string> changedProps = new List <string>(); NotifyCollectionChangedEventArgs args = null; collection.Add('A'); collection.Add('B'); collection.Add('C'); PropertyChangedEventHandler pceh = (sender, e) => { propertyChanged = true; changedProps.Add(e.PropertyName); }; // Adding a PropertyChanged event handler ((INotifyPropertyChanged)collection).PropertyChanged += pceh; collection.CollectionChanged += (sender, e) => { args = e; }; collection.CollectionChanged += (sender, e) => { // This one will attempt to break reentrancy try { collection.Add('X'); Assert.Fail("Reentrancy should not be allowed."); } catch (InvalidOperationException) { } }; collection[2] = 'I'; Assert.IsTrue(propertyChanged, "REENT_1"); Assert.IsTrue(changedProps.Contains("Item[]"), "REENT_2"); CollectionChangedEventValidators.ValidateReplaceOperation(args, new char[] { 'C' }, new char[] { 'I' }, 2, "REENT_3"); // Removing the PropertyChanged event handler should work as well: ((INotifyPropertyChanged)collection).PropertyChanged -= pceh; }