public MainWindowViewModel(DataRepository repo)
        {
            this.repo = repo.ThrowIfNull();

            feeds = new ObservableCollection<FeedViewModel>(
                repo.AllFeeds().Select(feed => new FeedViewModel(repo, feed)));
            feedItems = new ObservableCollection<FeedItemViewModel>(
                repo.AllFeedItems().Select(feedItem => new FeedItemViewModel(feedItem)));

            FeedsView = CollectionViewSource.GetDefaultView(feeds);
            FeedsView.CurrentChanged += HandleFeedsViewCurrentChanged;

            FeedItemsView = CollectionViewSource.GetDefaultView(feedItems);
            FeedItemsView.Filter = FeedItemsViewFilter;
            FeedItemsView.SortDescriptions.Add(new SortDescription("PublishDate",
                                                                   ListSortDirection.Descending));

            NewFeedCommand = new RelayCommand(param => NewFeed());
            ModifyFeedCommand = new RelayCommand(param => ModifyFeed());
            ClearFeedItemsFilterCommand = new RelayCommand(param => ClearFeedItemsFilter());

            repo.FeedAdded += HandleFeedAdded;
            repo.FeedModified += HandleFeedModified;
            repo.FeedDeleted += HandleFeedDeleted;
            repo.FeedItemsAdded += HandleFeedItemsAdded;

            FeedsView.MoveCurrentTo(null);
        }
        public void AllFeedItems_ReturnsAllFeedItems()
        {
            Feed feed = new Feed { Title = "test feed", Url = "url" };
            context.Feeds.Add(feed);
            context.FeedItems.Add(new FeedItem { Feed = feed, Title = "feed item 1" });
            context.FeedItems.Add(new FeedItem { Feed = feed, Title = "feed item 2" });
            context.FeedItems.Add(new FeedItem { Feed = feed, Title = "feed item 3" });
            context.SaveChanges();

            DataRepository underTest = new DataRepository(context);

            List<FeedItem> returnedFeedItems = new List<FeedItem>(underTest.AllFeedItems());

            Assert.AreEqual(context.FeedItems.Count(), returnedFeedItems.Count(),
                            "Returned AllFeedItems collection is the wrong length.");

            Assert.Contains(context.FeedItems.Single(fi => fi.Title == "feed item 1"), returnedFeedItems);
            Assert.Contains(context.FeedItems.Single(fi => fi.Title == "feed item 2"), returnedFeedItems);
            Assert.Contains(context.FeedItems.Single(fi => fi.Title == "feed item 3"), returnedFeedItems);
        }