public void NotifyCollectionChangedEventArgsConstructor9Test() { IList changed = new List <object>(); const int newIndex = 2; const int oldIndex = 5; // Trying with Replace var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changed, newIndex, oldIndex); CollectionChangedEventValidators.ValidateMoveOperation(args, changed, newIndex, oldIndex, "#I01"); // Add some items to test this one. changed.Add(new object()); changed.Add(new object()); changed.Add(new object()); // Trying with Replace again args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changed, newIndex, oldIndex); CollectionChangedEventValidators.ValidateMoveOperation(args, changed, newIndex, oldIndex, "#I02"); // Trying with newIndex < 0. try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changed, -5, oldIndex)); Assert.Fail("The index argument cannot be less than 0."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Reset try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Replace try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Add try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Add."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Remove try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove."); } catch (ArgumentException ex) { No.Op(ex); } }
public void NotifyCollectionChangedEventArgsConstructor10Test() { var changed = new object(); const int newIndex = 2; const int oldIndex = 5; // Trying with Replace var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changed, newIndex, oldIndex); CollectionChangedEventValidators.ValidateMoveOperation(args, new[] { changed }, newIndex, oldIndex, "#J01"); // Trying with newIndex < 0. try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changed, -5, oldIndex)); Assert.Fail("The newIndex argument cannot be less than 0."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Reset try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Replace try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Add try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Add."); } catch (ArgumentException ex) { No.Op(ex); } // Trying with Remove try { GC.KeepAlive(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, changed, newIndex, oldIndex)); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove."); } catch (ArgumentException ex) { No.Op(ex); } }