public void NotifyCollectionChangedEventArgsConstructor7Test() { object oldItem = new object(); object newItem = new object(); // Doesn't matter what the value of this is. // Trying with Add NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItem, oldItem); CollectionChangedEventValidators.ValidateReplaceOperation(args, new object[] { oldItem }, new object[] { newItem }, "#G01"); // Trying null items args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, (object)null, oldItem); CollectionChangedEventValidators.ValidateReplaceOperation(args, new object[] { oldItem }, new object[] { null }, "#G02"); args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItem, (object)null); CollectionChangedEventValidators.ValidateReplaceOperation(args, new object[] { null }, new object[] { newItem }, "#G03"); // Trying with Reset try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, newItem, oldItem); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset."); } catch (ArgumentException) { } // Trying with Move try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, newItem, oldItem); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Move."); } catch (ArgumentException) { } // Trying with Add try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newItem, oldItem); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Add."); } catch (ArgumentException) { } // Trying with Remove try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, newItem, oldItem); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove."); } catch (ArgumentException) { } }
public void NotifyCollectionChangedEventArgsConstructor11Test() { var newItem = new object(); var oldItem = new object(); const int startIndex = 5; // Trying with Replace var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItem, oldItem, startIndex); CollectionChangedEventValidators.ValidateReplaceOperation(args, new object[] { oldItem }, new object[] { newItem }, startIndex, "#K01"); // Trying with Reset try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, newItem, oldItem, startIndex); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Move try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, newItem, oldItem, startIndex); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Move."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Add try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newItem, oldItem, startIndex); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Add."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Remove try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, newItem, oldItem); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } }
public void NotifyCollectionChangedEventArgsConstructor8Test() { IList newItems = new List <object>(); IList oldItems = new List <object>(); const int startIndex = 5; // Trying with Replace var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex); CollectionChangedEventValidators.ValidateReplaceOperation(args, oldItems, newItems, startIndex, "#H01"); // Add some items to test this one. newItems.Add(new object()); newItems.Add(new object()); newItems.Add(new object()); // Trying with Replace again args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex); CollectionChangedEventValidators.ValidateReplaceOperation(args, oldItems, newItems, startIndex, "#H02"); // Add some more items to test this one. oldItems.Add(new object()); oldItems.Add(new object()); oldItems.Add(new object()); // Trying with Replace again args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex); CollectionChangedEventValidators.ValidateReplaceOperation(args, oldItems, newItems, startIndex, "#H03"); // Trying with null arguments. try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, null, oldItems, startIndex); Assert.Fail("The newItems argument cannot be null."); } catch (ArgumentNullException ex) { GC.KeepAlive(ex); } try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, null, startIndex); Assert.Fail("The oldItems argument cannot be null."); } catch (ArgumentNullException ex) { GC.KeepAlive(ex); } // Trying with Reset try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, newItems, oldItems, startIndex); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Move try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, newItems, oldItems, startIndex); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Move."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Add try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newItems, oldItems, startIndex); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Add."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Remove try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, newItems, oldItems); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } }
public void NotifyCollectionChangedEventArgsConstructor4Test() { /* Expected Behavior: * * If action is Replace: * If newItems is null, throw an ArgumentNullException. * If oldItems is null, throw an ArgumentNullException * Otherwise, success. * If action is not Replace, throw an ArgumentException */ IList newItems = new List <object>(); IList oldItems = new List <object>(); // Trying with Replace var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, oldItems); CollectionChangedEventValidators.ValidateReplaceOperation(args, oldItems, newItems, "#D01"); // Add some items to test this one. newItems.Add(new object()); newItems.Add(new object()); newItems.Add(new object()); // Trying with Replace again args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, oldItems); CollectionChangedEventValidators.ValidateReplaceOperation(args, oldItems, newItems, "#D02"); // Add some more items to test this one. oldItems.Add(new object()); oldItems.Add(new object()); oldItems.Add(new object()); // Trying with Replace again args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, oldItems); CollectionChangedEventValidators.ValidateReplaceOperation(args, oldItems, newItems, "#D03"); // Trying with null arguments. try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, null, oldItems); Assert.Fail("The newItems argument cannot be null."); } catch (ArgumentNullException ex) { GC.KeepAlive(ex); } try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItems, null); Assert.Fail("The oldItems argument cannot be null."); } catch (ArgumentNullException ex) { GC.KeepAlive(ex); } // Trying with Reset try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, newItems, oldItems); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Move try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, newItems, oldItems); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Move."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Add try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newItems, oldItems); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Add."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } // Trying with Remove try { args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, newItems, oldItems); Assert.Fail("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove."); } catch (ArgumentException ex) { GC.KeepAlive(ex); } }