Ejemplo n.º 1
0
            public void Remove_CurrentOnlyAndLastItem()
            {
                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.Remove(tracks[0]);

                Assert.AreEqual(0, queue.Count);
                Assert.AreEqual(null, queue.Current);
                Assert.AreEqual(-1, queue.Index);
                Assert.AreEqual(RepeatType.None, queue.Repeat);
                Assert.AreEqual(RepeatType.None, 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 == null && e.OldItems?.Count == 1).Count());
                Assert.AreEqual(1, collectionChangedEvents.Count);
            }
            public void Remove_CurrentAndLastItem()
            {
                var queue = new MediaQueue();

                var tracks = new[]
                {
                    new MediaFile(),
                    new MediaFile(),
                    new MediaFile(),
                };

                queue.AddRange(tracks);
                queue.SetIndexAsCurrent(2);

                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.Remove(tracks[2]);

                Assert.AreEqual(2, queue.Count);
                Assert.AreEqual(tracks[1], queue.Current);
                Assert.AreEqual(1, queue.Index);
                Assert.AreEqual(RepeatType.None, queue.Repeat);
                Assert.AreEqual(false, queue.IsShuffled);

                Assert.AreEqual(1, propertyChangedEvents.Count(e => e.PropertyName == nameof(queue.Current)));
                Assert.AreEqual(1, propertyChangedEvents.Count(e => e.PropertyName == nameof(queue.Index)));
                Assert.AreEqual(1, propertyChangedEvents.Count(e => e.PropertyName == nameof(queue.Count)));
                Assert.AreEqual(3, propertyChangedEvents.Count);
                Assert.AreEqual(1, collectionChangedEvents.Count(e => e.NewItems == null && e.OldItems?.Count == 1));
                Assert.AreEqual(1, collectionChangedEvents.Count);
            }