public void RemoveAt() { BaseCollection <int> collection = new BaseCollection <int>(new [] { 1, 2, 3 }); collection.RemoveAt(2); collection.RemoveAt(1); Assert.AreEqual(1, collection.Count()); Assert.AreEqual(1, collection[0]); }
/// <summary> /// Create a new instance. /// </summary> internal HeaderCollection(Document owner, ICollection <Header> fields) { foreach (var field in fields) { if (field.Owner != null) { throw new ArgumentOutOfRangeException(nameof(fields), "Item cannot be in other collection."); } } Owner = owner; BaseCollection.AddRange(fields); foreach (var field in fields) { field.Owner = this; } //ensure first field is always Version if (!Contains(HeaderType.Version)) { BaseCollection.Insert(0, new Header(HeaderType.Version, BitConverter.GetBytes(Header.DefaultVersion))); } else { var versionField = this[HeaderType.Version]; var versionIndex = IndexOf(versionField); if (versionIndex > 0) { BaseCollection.RemoveAt(versionIndex); BaseCollection.Insert(0, versionField); } } }
internal void AddPasswordToHistory(DateTime time, string password) { if (Enabled && !string.IsNullOrEmpty(password)) //change only if enabled and not empty { BaseCollection.Add(new PasswordHistoryItem(this, time, password)); while (BaseCollection.Count > MaximumCount) { BaseCollection.RemoveAt(0); } MarkAsChanged(); } }
/// <summary> /// <see cref="IList{T}.RemoveAt(int)" /> /// </summary> public void RemoveAt(int index) { var oldCount = Count; var oldItem = TryGetOldItem(index); BaseCollection.RemoveAt(index); if (oldCount != Count) { RaiseCollectionEvents(); var e = new NotifyCollectionChangedEventArgs(action: NotifyCollectionChangedAction.Remove, changedItem: oldItem, index: index); RaiseCollectionChanged(e); } }
public void CallEvents() { BaseCollection <int> collection = new BaseCollection <int>(); var setSubscriber = Substitute.For <IDummyEventSubscriber <IEnumerable <int> > >(); var addedSubscriber = Substitute.For <IDummyEventSubscriber <int> >(); var removedSubscriber = Substitute.For <IDummyEventSubscriber <int> >(); collection.OnSet += setSubscriber.React; collection.OnAdded += addedSubscriber.React; collection.OnRemoved += removedSubscriber.React; collection.Set(new [] { 1, 2, 3, 4 }); collection.Add(4); collection.Remove(2); collection.RemoveAt(0); setSubscriber.Received().React(collection.list); addedSubscriber.Received().React(4); removedSubscriber.Received().React(2); removedSubscriber.Received().React(1); }