public void inserts_new_content_for_noncached_feed() { string url = "http://new.feed/rss"; var newFeed = prepare_fake_feed(); A.CallTo( () => _remoteData.ReadRemoteSource( A <LocalFeedInfo> .That.Matches(x => x.Url == url && x.LastFetch == null)) ).Returns(new RemoteContentResponse(true, "new-etag", newFeed, HttpStatusCode.OK)); execute(url); List <LocalFeedInfo> fromDb = _feedsProvider.Db().LocalFeedInfo.All() .ToList <LocalFeedInfo>(); Assert.Equal(1, fromDb.Count); Assert.Equal(newFeed.GetRssString(), fromDb[0].Content); }
public void UpdateFeed(string url) { var db = _localFeedsProvider.Db(); dynamic read_view = GetLocalFeedInfoView(db); LocalFeedInfo feed = read_view.FindByUrl(url) ?? new LocalFeedInfo { Url = url, }; _log.Debug("Updating {0} feed '{1}'", feed.Id == 0 ? "new" : "existing", url); RemoteContentResponse remoteResponse = null; try { OnBeforeReadingRemoteSource(db, feed); remoteResponse = _remoteData.ReadRemoteSource(feed); } catch (Exception exc) { OnReadingRemoteSourceError(db, feed, remoteResponse, exc); throw; } if (remoteResponse.HasNewContent == false) { _log.Debug("Feed '{0}' does not have new content", url); OnNoNewContentInRemoteSource(db, feed, remoteResponse); return; } bool newFeed = feed.LastFetch == null; string previousContent = feed.Content ?? string.Empty; feed.Content = GetFeedStringContent(remoteResponse); feed.LastFetch = ApplicationTime.Current; feed.Etag = remoteResponse.Etag; if (newFeed) { _log.Info("Inserting new feed '{0}' to local cache", url); InsertNewFeed(db, feed, url); } else { _log.Info("Updating feed '{0}' in local cache", url); UpdateExistingFeed(db, feed, url); } OnFeedUpdated(db, feed, remoteResponse); if (previousContent.GetHashCode() == feed.Content.GetHashCode()) { _log.Warn("Wasting resources: updating feed '{0}' with the same content it already had!", url); } }