public void GetRssFeedsForUrlFindsAtomAndRssFeeds() { RssLocater locater = new RssLocater(null, null); var feeds = locater.GetRssFeedsForUrl(BASE_URL + "GetRssFeedsForUrl.html", true); Assert.AreEqual(4, feeds.Count); Assert.AreEqual(BASE_URL + "SampleRss0.91Feed.xml", feeds[0].ToString()); Assert.AreEqual(BASE_URL + "SampleRss0.92Feed.rss", feeds[1].ToString()); Assert.AreEqual(BASE_URL + "SampleRss1.0Feed.rss", feeds[2].ToString()); Assert.AreEqual(BASE_URL + "SampleRss2.0Feed.xml", feeds[3].ToString()); feeds = locater.GetRssFeedsForUrl(BASE_URL + "LinksToExternalFeed.htm", true); Assert.AreEqual(1, feeds.Count); }
public void GetRssFeedsForUrlDoesNotFindPhantomFeeds() { RssLocater locater = new RssLocater(null, null); var feeds = locater.GetRssFeedsForUrl(BASE_URL + "NoFeeds.html", true); Assert.AreEqual(0, feeds.Count, "Impossibly, we found a feed where there are none."); }
public void GetRssFeedsForUrlDoesNotThrowExceptionWhen404Encountered() { RssLocater locater = new RssLocater(null, null); var feeds = locater.GetRssFeedsForUrl(BASE_URL + "FileNotFound.html", false); Assert.AreEqual(0, feeds.Count); }
public void GetRssFeedsForUrlFindsFeedProtocolUrls() { RssLocater locater = new RssLocater(null, null); var feeds = locater.GetRssFeedsForUrl(BASE_URL + "feedProtocol.htm", true); Assert.AreEqual(3, feeds.Count); Assert.AreEqual(BASE_URL + "SampleRss0.91Feed.xml", feeds[0].ToString()); Assert.AreEqual(BASE_URL + "SampleRss0.92Feed.rss", feeds[1].ToString()); Assert.AreEqual(BASE_URL + "SampleRss2.0Feed.xml", feeds[2].ToString()); }
/// <summary> /// Implentation required for the Thread start call /// </summary> /// <example> /// Here is the impl. recommendation: /// <code> /// try { /// // long running task /// } catch (System.Threading.ThreadAbortException) { /// // eat up: op. cancelled /// } catch(Exception ex) { /// // handle them, or publish: /// p_operationException = ex; /// } finally { /// this.WorkDone.Set(); // signal end of operation to dismiss the dialog /// } /// </code> /// </example> protected override void Run() { RssLocater locator = new RssLocater(proxy, RssBanditApplication.UserAgent, this.Credentials); List <string> arrFeedUrls; Dictionary <string, string[]> htFeedUrls = null; // can raise System.Net.WebException: The remote server returned an error: (403) Forbidden try { if (locationMethod == FeedLocationMethod.AutoDiscoverUrl) { arrFeedUrls = locator.GetRssFeedsForUrl(webPageUrl, true); htFeedUrls = new Dictionary <string, string[]>(arrFeedUrls.Count); foreach (string rssurl in arrFeedUrls) { NewsFeed discoveredFeed = new NewsFeed(); discoveredFeed.link = rssurl; IFeedDetails feedInfo; try { // can raise System.Net.WebException: The remote server returned an error: (403) Forbidden feedInfo = RssParser.GetItemsForFeed(discoveredFeed, this.GetWebResponseStream(rssurl), false); } catch (Exception) { // fatal errors feedInfo = FeedInfo.Empty; } htFeedUrls.Add(rssurl, new string[] { (!string.IsNullOrEmpty(feedInfo.Title) ? feedInfo.Title: SR.AutoDiscoveredDefaultTitle), feedInfo.Description, feedInfo.Link, rssurl }); } } else // Syndic8SearchType.Keyword { htFeedUrls = locator.GetFeedsFromSyndic8(searchTerms, locationMethod); } } catch (ThreadAbortException) { // eat up } catch (System.Net.WebException wex) { p_operationException = wex; // Would it make sense, to display a credentials dialog for error (403) here? // MessageBox.Show( // SR.WebExceptionOnUrlAccess(webPageUrl, wex.Message), // SR.GUIAutoDiscoverFeedFailedCaption, MessageBoxButtons.OK,MessageBoxIcon.Error); htFeedUrls = new Dictionary <string, string[]>(); } catch (Exception e) { // fatal errors p_operationException = e; // MessageBox.Show( // SR.WebExceptionOnUrlAccess(webPageUrl, e.Message), // SR.GUIAutoDiscoverFeedFailedCaption, MessageBoxButtons.OK,MessageBoxIcon.Error); htFeedUrls = new Dictionary <string, string[]>(); } finally { discoveredFeeds = htFeedUrls; WorkDone.Set(); } }
public void GetRssAutoDiscoveryLinksFindsRssLinks() { RssLocater locater = new RssLocater(null, null); var feeds = locater.GetRssAutoDiscoveryLinks(BASE_URL + "GetRssAutoDiscoveryLinks.html"); Assert.AreEqual(4, feeds.Count, "Obviously I could not count as I expected 4 feeds."); Assert.AreEqual(BASE_URL + "SampleRss0.91Feed.xml", (string)feeds[0]); Assert.AreEqual(BASE_URL + "SampleRss0.92Feed.rss", (string)feeds[1]); Assert.AreEqual(BASE_URL + "SampleRss1.0Feed.rss", (string)feeds[2]); Assert.AreEqual(BASE_URL + "SampleRss2.0Feed.xml", (string)feeds[3], "Missing version 2.0. Stuck in the past."); feeds = locater.GetRssFeedsForUrl(BASE_URL + "AutoDiscovery1.htm", true); Assert.AreEqual(feeds.Count, 2); }
public void GetRssFeedsForUrlFindsLinksToWellKnownListeners() { RssLocater locater = new RssLocater(null, null); var feeds = locater.GetRssFeedsForUrl(BASE_URL + "localListeners.htm", true); Assert.AreEqual(8, feeds.Count); Assert.AreEqual(BASE_URL + "SampleRss0.91Feed.xml", feeds[0].ToString()); Assert.AreEqual(BASE_URL + "SampleRss0.92Feed.rss", feeds[1].ToString()); Assert.AreEqual(BASE_URL + "SampleRss1.0Feed.rss", feeds[2].ToString()); Assert.AreEqual(BASE_URL + "SampleRss2.0Feed.xml", feeds[3].ToString()); Assert.AreEqual(BASE_URL + "SampleFeed001Rss2.0.rss", feeds[4].ToString()); Assert.AreEqual(BASE_URL + "SampleFeed002Rss2.0.rss", feeds[5].ToString()); Assert.AreEqual(BASE_URL + "SampleFeed003Rss2.0.rss", feeds[6].ToString()); Assert.AreEqual(BASE_URL + "SampleFeed004Rss2.0.rss", feeds[7].ToString()); }