public void Clear_INotifyPropertyChangedItems_RemovesPropertyChangedEventHandlers() { var item1 = new Item(); var item2 = new Item(); var list = new List <Item> { item1, item2, null }; var bindingList = new CiccioSet <Item>(list); Assert.Equal(1, item1.InvocationList.Length); Assert.Equal(1, item2.InvocationList.Length); bool calledListChanged = false; bindingList.ListChanged += (object sender, ListChangedEventArgs e) => { calledListChanged = true; Assert.Equal(ListChangedType.Reset, e.ListChangedType); Assert.Equal(-1, e.NewIndex); }; bindingList.Clear(); Assert.True(calledListChanged); Assert.Empty(bindingList); Assert.Null(item1.InvocationList); Assert.Null(item2.InvocationList); }
/// <summary> /// Clears the given Collection. /// </summary> public void ClearTest(CiccioSet <string> collection) { INotifyPropertyChanged collectionPropertyChanged = collection; collectionPropertyChanged.PropertyChanged += Collection_PropertyChanged; _expectedPropertyChanged = new[] { new PropertyNameExpected(COUNT), //new PropertyNameExpected(ITEMARRAY) }; collection.CollectionChanged += Collection_CollectionChanged; ExpectedCollectionChangedFired++; ExpectedAction = NotifyCollectionChangedAction.Reset; ExpectedNewItems = null; ExpectedNewStartingIndex = -1; ExpectedOldItems = null; ExpectedOldStartingIndex = -1; collection.Clear(); Assert.Equal(0, collection.Count); Assert.Equal(ExpectedCollectionChangedFired, NumCollectionChangedFired); foreach (var item in _expectedPropertyChanged) { Assert.True(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since we just cleared the collection"); } collection.CollectionChanged -= Collection_CollectionChanged; collectionPropertyChanged.PropertyChanged -= Collection_PropertyChanged; }
public static void ClearTest() { string[] anArray = { "one", "two", "three", "four" }; CiccioSet <string> col = new CiccioSet <string>(anArray); col.Clear(); Assert.Equal(0, col.Count); Assert.Empty(col); //AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => col.ToArray()[1]); //tests that the collectionChanged events are fired. CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester(); col = new CiccioSet <string>(anArray); helper.ClearTest(col); }
public void Clear_Invoke_Success() { var bindingList = new CiccioSet <object> { new object(), new object() }; bool calledListChanged = false; bindingList.ListChanged += (object sender, ListChangedEventArgs e) => { calledListChanged = true; Assert.Equal(ListChangedType.Reset, e.ListChangedType); Assert.Equal(-1, e.NewIndex); }; bindingList.Clear(); Assert.True(calledListChanged); Assert.Empty(bindingList); }