public Insert ( int index, IMediaFile item ) : void | ||
index | int | |
item | IMediaFile | |
return | void |
public void Insert_OutOfRange() { var queue = new MediaQueue(); var tracks = new[] { new MediaFile(), }; queue.AddRange(tracks); queue.SetIndexAsCurrent(0); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); Assert.Throws<ArgumentOutOfRangeException>(() => { queue.Insert(2, new MediaFile()); }); Assert.AreEqual(1, queue.Count); Assert.AreEqual(tracks[0], queue.Current); Assert.AreEqual(0, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(false, queue.Shuffle); Assert.AreEqual(0, propertyChangedEvents.Count); Assert.AreEqual(0, collectionChangedEvents.Count); }
public void Insert_Empty() { var queue = new MediaQueue(); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); var newMediaFile = new MediaFile(); queue.Insert(0, newMediaFile); Assert.AreEqual(1, queue.Count); Assert.AreEqual(newMediaFile, queue.Current); Assert.AreEqual(0, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(false, queue.Shuffle); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Current").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Index").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Count").Count()); Assert.AreEqual(3, propertyChangedEvents.Count); Assert.AreEqual(1, collectionChangedEvents.Where(e => e.NewItems?.Count == 1 && e.OldItems == null).Count()); Assert.AreEqual(1, collectionChangedEvents.Count); }
public void Insert_OutOfRange_Empty() { var queue = new MediaQueue(); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); var newMediaFile = new MediaFile(); Assert.Throws<ArgumentOutOfRangeException>(() => { queue.Insert(1, newMediaFile); }); Assert.AreEqual(0, queue.Count); Assert.AreEqual(null, queue.Current); Assert.AreEqual(-1, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(false, queue.Shuffle); Assert.AreEqual(0, propertyChangedEvents.Count); Assert.AreEqual(0, collectionChangedEvents.Count); }
public void Insert_PostCurrent() { var queue = new MediaQueue(); var tracks = new[] { new MediaFile(), }; queue.AddRange(tracks); queue.SetIndexAsCurrent(0); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); queue.Insert(1, new MediaFile()); Assert.AreEqual(2, queue.Count); Assert.AreEqual(tracks[0], queue.Current); Assert.AreEqual(0, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(false, queue.Shuffle); Assert.AreEqual(0, propertyChangedEvents.Where(e => e.PropertyName == "Current").Count()); Assert.AreEqual(0, propertyChangedEvents.Where(e => e.PropertyName == "Index").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Count").Count()); Assert.AreEqual(1, propertyChangedEvents.Count); Assert.AreEqual(1, collectionChangedEvents.Where(e => e.NewItems?.Count == 1 && e.OldItems == null).Count()); Assert.AreEqual(1, collectionChangedEvents.Count); }