public void SetDefaultSelectedFeedItem(Feed feed, FeedItem feedItem) { if (feedItem != null && !lastSelectedFeedItems.ContainsKey(feed)) { lastSelectedFeedItems[feed] = feedItem; } }
public void ApplyValuesFrom(FeedItem item, bool excludeMarkAsRead = false) { if (Uri != item.Uri) { throw new InvalidOperationException("The Uri must be the same."); } Date = item.Date; Name = item.Name; Description = item.Description; Author = item.Author; if (!excludeMarkAsRead) { MarkAsRead = item.MarkAsRead; } }
public void SupportNull() { var item = new FeedItem(new Uri("http://www.test.com/rss/feed"), new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), "name", "desc", "author"); item.Name = null; item.Description = null; item.Author = null; Assert.IsNull(item.Name); Assert.IsNull(item.Description); Assert.IsNull(item.Author); }
public void CloneTest() { var item = new FeedItem(new Uri("http://www.test.com/rss/feed"), new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), "name", "desc", "author"); item.MarkAsRead = true; var clone = item.Clone(); Assert.AreNotSame(item, clone); Assert.AreEqual(new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), clone.Date); Assert.AreEqual("name", clone.Name); Assert.AreEqual("desc", clone.Description); Assert.AreEqual("author", clone.Author); Assert.IsTrue(clone.MarkAsRead); }
public void MergeTest() { var feedManagerA = new FeedManager(); feedManagerA.Feeds.Remove(feedManagerA.Feeds.Single()); var feedA1 = new Feed(new Uri("http://www.test.com/rss/feedA1")); var feedA2 = new Feed(new Uri("http://www.test.com/rss/feedA2")); feedManagerA.Feeds.Add(feedA1); feedManagerA.Feeds.Add(feedA2); var item = new FeedItem(new Uri("http://www.test.com/rss/feed"), new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), "name", "desc", "author"); feedA2.UpdateItems(new[] { item }); Assert.IsFalse(feedManagerA.Feeds.Last().Items.Single().MarkAsRead); var feedManagerB = new FeedManager() { ItemLifetime = TimeSpan.FromDays(42), MaxItemsLimit = 43 }; feedManagerB.Feeds.Remove(feedManagerB.Feeds.Single()); var feedB1 = new Feed(new Uri("http://www.test.com/rss/feedB1")); var feedB2 = new Feed(new Uri("http://www.test.com/rss/feedA2")); feedManagerB.Feeds.Add(feedB1); feedManagerB.Feeds.Add(feedB2); feedB2.UpdateItems(new[] { item }, cloneItemsBeforeInsert: true); feedB2.Items.Single().MarkAsRead = true; feedManagerA.Merge(feedManagerB); Assert.AreEqual(42, feedManagerA.ItemLifetime.Value.Days); Assert.AreEqual(43u, feedManagerA.MaxItemsLimit.Value); Assert.IsTrue(new[] { "http://www.test.com/rss/feedB1", "http://www.test.com/rss/feedA2" }.SequenceEqual(feedManagerA.Feeds.Select(x => x.Uri.ToString()))); Assert.IsTrue(feedManagerA.Feeds.Last().Items.Single().MarkAsRead); // Just remove one element => this way the Merge does not create new instances var feedManagerC = new FeedManager(); feedManagerC.Feeds.Remove(feedManagerC.Feeds.Single()); var feedC2 = new Feed(new Uri("http://www.test.com/rss/feedA2")); feedManagerC.Feeds.Add(feedC2); feedC2.UpdateItems(new[] { item }, cloneItemsBeforeInsert: true); feedC2.Items.Single().MarkAsRead = false; var itemA = feedManagerA.Feeds.Last().Items.Single(); feedManagerA.Merge(feedManagerC); Assert.IsTrue(new[] { "http://www.test.com/rss/feedA2" }.SequenceEqual(feedManagerA.Feeds.Select(x => x.Uri.ToString()))); Assert.AreSame(itemA, feedManagerA.Feeds.Last().Items.Single()); Assert.IsFalse(itemA.MarkAsRead); }
public void ApplyValuesFromTest() { AssertHelper.ExpectedException<ArgumentNullException>(() => new FeedItem(null, DateTimeOffset.Now, "test", "test", "test")); var itemA1 = new FeedItem(new Uri("http://www.test.com/rss/feed"), new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), "name", "desc", "author"); Assert.AreEqual(new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), itemA1.Date); Assert.AreEqual("name", itemA1.Name); Assert.AreEqual("desc", itemA1.Description); Assert.AreEqual("author", itemA1.Author); Assert.IsFalse(itemA1.MarkAsRead); var itemA2 = new FeedItem(new Uri("http://www.test.com/rss/feed"), new DateTimeOffset(2022, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), "name2", "desc2", "author2"); itemA2.MarkAsRead = true; itemA1.ApplyValuesFrom(itemA2); Assert.AreEqual(new DateTimeOffset(2022, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), itemA1.Date); Assert.AreEqual("name2", itemA1.Name); Assert.AreEqual("desc2", itemA1.Description); Assert.AreEqual("author2", itemA1.Author); Assert.IsTrue(itemA1.MarkAsRead); var itemB1 = new FeedItem(new Uri("http://www.test.com/rss/feed2"), new DateTimeOffset(2020, 5, 5, 12, 0, 0, new TimeSpan(1, 0, 0)), "name", "desc", "author"); AssertHelper.ExpectedException<InvalidOperationException>(() => itemA1.ApplyValuesFrom(itemB1)); }