public void Clear() { List <char> initial = new List <char>(); initial.Add('A'); initial.Add('B'); initial.Add('C'); ObservableList <char> collection = new ObservableList <char>(initial); bool propertyChanged = false; List <string> changedProps = new List <string>(); NotifyCollectionChangedEventArgs args = null; ((INotifyPropertyChanged)collection).PropertyChanged += (sender, e) => { propertyChanged = true; changedProps.Add(e.PropertyName); }; collection.CollectionChanged += (sender, e) => { args = e; }; collection.Clear(); Assert.IsTrue(propertyChanged, "CLEAR_1"); Assert.IsTrue(changedProps.Contains("Count"), "CLEAR_2"); Assert.IsTrue(changedProps.Contains("Item[]"), "CLEAR_3"); CollectionChangedEventValidators.ValidateResetOperation(args, "CLEAR_4"); }
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 Add() { ObservableList <char> collection = new ObservableList <char>(); bool propertyChanged = false; List <string> changedProps = new List <string>(); NotifyCollectionChangedEventArgs args = null; ((INotifyPropertyChanged)collection).PropertyChanged += (sender, e) => { propertyChanged = true; changedProps.Add(e.PropertyName); }; collection.CollectionChanged += (sender, e) => { args = e; }; collection.Add('A'); Assert.IsTrue(propertyChanged, "ADD_1"); Assert.IsTrue(changedProps.Contains("Count"), "ADD_2"); Assert.IsTrue(changedProps.Contains("Item[]"), "ADD_3"); CollectionChangedEventValidators.ValidateAddOperation(args, new char[] { 'A' }, 0, "ADD_4"); }
internal void DoubleEnterReentrant() { IDisposable object1 = BlockReentrancy(); IDisposable object2 = BlockReentrancy(); Assert.AreSame(object1, object2); //With double block, try the reentrant: NotifyCollectionChangedEventArgs args = null; CollectionChanged += (sender, e) => { args = e; }; // We need a second callback for reentrancy to matter CollectionChanged += (sender, e) => { // Doesn't need to do anything; just needs more than one callback registered. }; // Try adding - this should cause reentrancy, and fail try { Add('I'); Assert.Fail("Reentrancy should not be allowed. -- #2"); } catch (InvalidOperationException) { } // Release the first reentrant object1.Dispose(); // Try adding again - this should cause reentrancy, and fail again try { Add('J'); Assert.Fail("Reentrancy should not be allowed. -- #3"); } catch (InvalidOperationException) { } // Release the reentrant a second time object1.Dispose(); // This last add should work fine. Add('K'); CollectionChangedEventValidators.ValidateAddOperation(args, new char[] { 'K' }, 0, "REENTHELP_1"); }
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; }