public void Should_raise_changed_event_when_adding_deleting_and_manual()
        {
            var changedEvents = new List <NotifyCollectionChangedEventArgs>();
            var collection    = new CustomObservableCollection <string>();

            collection.CollectionChanged += (s, e) => changedEvents.Add(e);

            collection.Add("one");
            collection.Add("two");
            collection.Remove("one");
            collection.RaiseCollectionChanged();

            Assert.AreEqual(4, changedEvents.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[0].Action);
            Assert.AreEqual("one", changedEvents[0].NewItems.OfType <string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[1].Action);
            Assert.AreEqual("two", changedEvents[1].NewItems.OfType <string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, changedEvents[2].Action);
            Assert.AreEqual("one", changedEvents[2].OldItems.OfType <string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvents[3].Action);
        }
Exemplo n.º 2
0
        public MediaItem AddNewMediaItem(string name, Uri originalUri)
        {
            var newMediaItem = new MediaItem { Name = name, IsAvailable = false };
            MediaItems.Add(newMediaItem);

            log.Info("Adding item {0} (url: {1}) to library", name, originalUri);

            var client = new WebClient();
            client.OpenReadCompleted += (s, e) =>
            {
                log.Info("Item {0} (url: {1}) download complete.", name, originalUri);
                newMediaItem.DataStream = () => e.Result;
                newMediaItem.IsAvailable = true;
                mediaItemPersister.Save(newMediaItem);
                mediaItems.RaiseCollectionChanged();
            };
            client.DownloadProgressChanged += (s, e) =>
            {
                newMediaItem.DownloadProgress = e.ProgressPercentage;
            };
            client.OpenReadAsync(originalUri);

            return newMediaItem;
        }
        public void Should_raise_changed_event_when_adding_deleting_and_manual()
        {
            var changedEvents = new List<NotifyCollectionChangedEventArgs>();
            var collection = new CustomObservableCollection<string>();
            collection.CollectionChanged += (s, e) => changedEvents.Add(e);

            collection.Add("one");
            collection.Add("two");
            collection.Remove("one");
            collection.RaiseCollectionChanged();

            Assert.AreEqual(4, changedEvents.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[0].Action);
            Assert.AreEqual("one", changedEvents[0].NewItems.OfType<string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[1].Action);
            Assert.AreEqual("two", changedEvents[1].NewItems.OfType<string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, changedEvents[2].Action);
            Assert.AreEqual("one", changedEvents[2].OldItems.OfType<string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvents[3].Action);
        }
Exemplo n.º 4
0
 public void Update(Feed feed)
 {
     Save();
     feeds.RaiseCollectionChanged();
 }