public void Basic() { 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 tracks = new[] { new MediaFile(), new MediaFile(), }; queue.Add(tracks[0]); 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(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); queue.Add(tracks[1]); Assert.AreEqual(2, 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(1, propertyChangedEvents.Where(e => e.PropertyName == "Current").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Index").Count()); Assert.AreEqual(2, propertyChangedEvents.Where(e => e.PropertyName == "Count").Count()); Assert.AreEqual(4, propertyChangedEvents.Count); Assert.AreEqual(2, collectionChangedEvents.Where(e => e.NewItems.Count == 1 && e.OldItems == null).Count()); Assert.AreEqual(2, collectionChangedEvents.Count); }
public void WhenAddingItemsWhileShuffled_OrderIsSameAsBeforeButWithExtraItem() { var arr = new[] { new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile() }; Console.WriteLine("Original: {0}", string.Join(",", arr.Select(x => x.Id))); var queue = new MediaQueue(); Console.WriteLine("Current Index: {0}", queue.Index); queue.AddRange(arr); queue.ToggleShuffle(); queue.Add(new MediaFile()); Console.WriteLine("Shuffled: {0}", string.Join(",", queue.Cast <MediaFile>().Select(x => x.Id))); queue.ToggleShuffle(); Console.WriteLine("Unshuffled: {0}", string.Join(",", queue.Cast <MediaFile>().Select(x => x.Id))); CollectionAssert.AllItemsAreUnique(queue.Cast <MediaFile>().Select(x => x.Id)); Assert.AreEqual(arr[0].Id, queue.Cast <MediaFile>().ElementAt(0).Id); Assert.AreEqual(arr[1].Id, queue.Cast <MediaFile>().ElementAt(1).Id); Assert.AreEqual(arr[2].Id, queue.Cast <MediaFile>().ElementAt(2).Id); Assert.AreEqual(arr[3].Id, queue.Cast <MediaFile>().ElementAt(3).Id); Assert.AreEqual(arr[4].Id, queue.Cast <MediaFile>().ElementAt(4).Id); Assert.AreEqual(arr[5].Id, queue.Cast <MediaFile>().ElementAt(5).Id); Assert.AreEqual(arr[6].Id, queue.Cast <MediaFile>().ElementAt(6).Id); Assert.AreEqual(arr[7].Id, queue.Cast <MediaFile>().ElementAt(7).Id); Assert.AreEqual(arr[8].Id, queue.Cast <MediaFile>().ElementAt(8).Id); Assert.AreEqual(arr[9].Id, queue.Cast <MediaFile>().ElementAt(9).Id); Assert.AreEqual(arr[10].Id, queue.Cast <MediaFile>().ElementAt(10).Id); Assert.AreEqual(99, queue.Cast <MediaFile>().Last().Id); Assert.AreEqual(arr.Length + 1, queue.Count, "The array length is different"); }