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);
        }
示例#2
0
 public FeedViewModel(DataRepository repo, Feed feed) : base(feed)
 {
     this.repo = repo.ThrowIfNull();
     ProcessFeedCommand = new RelayCommand(param => ProcessFeed(), param => true);
     SaveFeedCommand = new RelayCommand(param => SaveFeed(), param => true);
     DeleteFeedCommand = new RelayCommand(param => DeleteFeed());
 }
示例#3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            repo = new DataRepository(new DB());

            MainWindow mainWindow = new MainWindow();
            MainWindow.DataContext = new MainWindowViewModel(repo);
            mainWindow.Show();
        }
        public void AddFeed_WithValidFeed_AddsAndSavesFeed()
        {
            Feed newFeed = new Feed { Title = "new feed", Url = "url" };
            DataRepository underTest = new DataRepository(context);

            underTest.AddFeed(newFeed);

            Assert.Contains(newFeed, context.Feeds.ToList());
        }
        public void DeleteFeed_WithValidFeed_DeletesFeed()
        {
            context.Feeds.Add(new Feed { Title = "test feed 1", Url = "url" });
            context.SaveChanges();

            DataRepository underTest = new DataRepository(context);

            Feed feedToDelete = context.Feeds.First();
            underTest.DeleteFeed(feedToDelete);

            Assert.IsFalse(context.Feeds.Any(f => f.ID == feedToDelete.ID));
        }
        public void AllFeeds_ReturnsAllFeeds()
        {
            context.Feeds.Add(new Feed { Title = "test feed 1", Url = "url" });
            context.Feeds.Add(new Feed { Title = "test feed 2", Url = "url" });
            context.Feeds.Add(new Feed { Title = "test feed 3", Url = "url" });
            context.SaveChanges();

            DataRepository underTest = new DataRepository(context);

            List<Feed> returnedFeeds = new List<Feed>(underTest.AllFeeds());

            Assert.AreEqual(context.Feeds.Count(), returnedFeeds.Count(),
                            "Returned AllFeeds collection is the wrong length.");

            Assert.Contains(context.Feeds.Single(f => f.Title == "test feed 1"), returnedFeeds);
            Assert.Contains(context.Feeds.Single(f => f.Title == "test feed 2"), returnedFeeds);
            Assert.Contains(context.Feeds.Single(f => f.Title == "test feed 3"), returnedFeeds);
        }
        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);
        }
        public void FeedExists_WhenFeedDoesNotExist_ReturnsFalse()
        {
            DataRepository underTest = new DataRepository(context);
            Feed nonExistantFeed = new Feed { Title = "feed", Url = "url" };

            Assert.IsFalse(underTest.FeedExists(nonExistantFeed));
        }
        public void ModifyFeed_WithValidFeed_ModifiesAndSavesChangesToFeed()
        {
            context.Feeds.Add(new Feed { Title = "test feed 1", Url = "url" });
            context.SaveChanges();

            DataRepository underTest = new DataRepository(context);

            Feed feedToModify = context.Feeds.First();
            feedToModify.Title += " MODIFIED";
            underTest.ModifyFeed(feedToModify);

            var feedTitleProperty = context.Entry(feedToModify).Property(f => f.Title);
            Assert.AreEqual(feedTitleProperty.CurrentValue, feedTitleProperty.OriginalValue);
        }
        public void FeedExists_WhenFeedExists_ReturnsTrue()
        {
            Feed existingFeed = new Feed { Title = "feed", Url = "url" };
            context.Feeds.Add(existingFeed);
            context.SaveChanges();

            DataRepository underTest = new DataRepository(context);

            Assert.IsTrue(underTest.FeedExists(existingFeed));
        }
        public void SetUp()
        {
            mockContext = new Mock<IDB>();
            mockFeedSet = new Mock<DbSet<Feed>>();
            mockFeedItemSet = new Mock<DbSet<FeedItem>>();

            mockContext.Setup(m => m.Feeds).Returns(mockFeedSet.Object);
            mockContext.Setup(m => m.FeedItems).Returns(mockFeedItemSet.Object);

            // Do nothing for call to Include.
            mockFeedItemSet.Setup(m => m.Include(It.IsAny<string>())).Returns(mockFeedItemSet.Object);

            singleFeed = new Feed { ID = 42, Url = "http://www.something.com", Title = "Something" };

            repoUnderTest = new DataRepository(mockContext.Object);
        }