예제 #1
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());
 }
        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());
        }
예제 #3
0
        public void AddFeed(Feed feed)
        {
            feed.ThrowIfNull();

            db.Feeds.Add(feed);
            db.SaveChanges();

            if (FeedAdded != null)
            {
                FeedAdded(this, new FeedAddedEventArgs(feed));
            }
        }
예제 #4
0
        public void DeleteFeed(Feed feed)
        {
            feed.ThrowIfNull();

            // Feed deletion handlers need relationships to FeedItem entities to be intact, so fire
            // event before db deletion.
            if (FeedDeleted != null)
            {
                FeedDeleted(this, new FeedDeletedEventArgs(feed));
            }

            db.Feeds.Remove(feed);
            db.SaveChanges();
        }
        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 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));
        }
예제 #8
0
 public void EndEdit()
 {
     cache = null;
 }
예제 #9
0
 public void CancelEdit()
 {
     Title = cache.Title;
     Url = cache.Url;
     FeedItems = cache.FeedItems;
     cache = null;
 }
예제 #10
0
 public void BeginEdit()
 {
     cache = new Feed
     {
         Title = this.Title,
         Url = this.Url,
         FeedItems = new ObservableCollection<FeedItem>(this.FeedItems)
     };
 }
예제 #11
0
 public FeedDeletedEventArgs(Feed deletedFeed)
 {
     DeletedFeed = deletedFeed.ThrowIfNull();
 }
예제 #12
0
 public FeedAddedEventArgs(Feed addedFeed)
 {
     AddedFeed = addedFeed.ThrowIfNull();
 }
예제 #13
0
 public FeedModifiedEventArgs(Feed modifiedFeed)
 {
     ModifiedFeed = modifiedFeed.ThrowIfNull();
 }
        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);
        }
예제 #15
0
        public void ModifyFeed(Feed feed)
        {
            feed.ThrowIfNull();
            if (db.GetEntityState(feed) != EntityState.Modified) return;

            db.SaveChanges();

            if (FeedModified != null)
            {
                FeedModified(this, new FeedModifiedEventArgs(feed));
            }
        }
예제 #16
0
        public bool FeedExists(Feed feed)
        {
            feed.ThrowIfNull();

            return db.Feeds.Any(f => f.ID == feed.ID);
        }