public static void RemoveAtTest_Negative() { Guid[] anArray = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; CiccioList <Guid> collection = new CiccioList <Guid>(anArray); collection.CollectionChanged += (o, e) => { throw new ShouldNotBeInvokedException(); }; int[] iArrInvalidValues = new int[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, int.MinValue }; foreach (var index in iArrInvalidValues) { AssertExtensions.Throws <ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index)); Assert.Equal(anArray.Length, collection.Count); } int[] iArrLargeValues = new int[] { collection.Count, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 }; foreach (var index in iArrLargeValues) { AssertExtensions.Throws <ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index)); Assert.Equal(anArray.Length, collection.Count); } }
public static void RemoveAtTest() { Guid[] anArray = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; CiccioList <Guid> col0 = new CiccioList <Guid>((IEnumerable <Guid>)anArray); CiccioList <Guid> col1 = new CiccioList <Guid>((IEnumerable <Guid>)anArray); CiccioList <Guid> col2 = new CiccioList <Guid>((IEnumerable <Guid>)anArray); col0.RemoveAt(0); string collectionString = ""; foreach (var item in col1) { collectionString += item + ", "; } Assert.False(col0.Contains(anArray[0]), "Collection0 should no longer contain the item: " + anArray[0] + " Collection: " + collectionString); col1.RemoveAt(1); collectionString = ""; foreach (var item in col1) { collectionString += item + ", "; } Assert.False(col1.Contains(anArray[1]), "Collection1 should no longer contain the item: " + anArray[1] + " Collection: " + collectionString); col2.RemoveAt(2); collectionString = ""; foreach (var item in col2) { collectionString += item + ", "; } Assert.False(col2.Contains(anArray[2]), "Collection2 should no longer contain the item: " + anArray[2] + " Collection: " + collectionString); string[] anArrayString = { "one", "two", "three", "four" }; CiccioList <string> col = new CiccioList <string>(anArrayString); CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester(); helper.RemoveItemAtTest(col, 1); }
/// <summary> /// Verifies that the item is removed from a given index in the collection. /// </summary> public void RemoveItemAtTest(CiccioList <string> collection, int itemIndex) { INotifyPropertyChanged collectionPropertyChanged = collection; collectionPropertyChanged.PropertyChanged += Collection_PropertyChanged; _expectedPropertyChanged = new[] { new PropertyNameExpected(COUNT), new PropertyNameExpected(ITEMARRAY) }; collection.CollectionChanged += Collection_CollectionChanged; string itemAtOldIndex = collection[itemIndex]; ExpectedCollectionChangedFired++; ExpectedAction = NotifyCollectionChangedAction.Remove; ExpectedNewItems = null; ExpectedNewStartingIndex = -1; ExpectedOldItems = new string[] { itemAtOldIndex }; ExpectedOldStartingIndex = itemIndex; int expectedCount = collection.Count - 1; collection.RemoveAt(itemIndex); Assert.Equal(expectedCount, 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 removed an item"); } collection.CollectionChanged -= Collection_CollectionChanged; collectionPropertyChanged.PropertyChanged -= Collection_PropertyChanged; }