Exemplo n.º 1
0
            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(RepeatType.None, queue.Shuffle);

                Assert.AreEqual(0, propertyChangedEvents.Count);
                Assert.AreEqual(0, collectionChangedEvents.Count);
            }
Exemplo n.º 2
0
            public void Insert_PreCurrent()
            {
                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(0, new MediaFile());

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

                Assert.AreEqual(0, 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(2, propertyChangedEvents.Count);
                Assert.AreEqual(1, collectionChangedEvents.Where(e => e.NewItems?.Count == 1 && e.OldItems == null).Count());
                Assert.AreEqual(1, collectionChangedEvents.Count);
            }
            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(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);
            }
Exemplo n.º 4
0
            public void SetNotCurrent()
            {
                var queue = new MediaQueue();

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

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

                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[0] = new MediaFile();

                Assert.AreEqual(3, queue.Count);
                Assert.AreEqual(tracks[1], 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(1, collectionChangedEvents.Where(e => e.NewItems?.Count == 1 && e.OldItems?.Count == 1).Count());
                Assert.AreEqual(1, collectionChangedEvents.Count);
            }
            public void SetNull()
            {
                var queue = new MediaQueue();

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

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

                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 <ArgumentNullException>(() =>
                {
                    queue[1] = null;
                });

                Assert.AreEqual(3, 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(0, propertyChangedEvents.Count);
                Assert.AreEqual(0, collectionChangedEvents.Count);
            }