示例#1
0
 public void FeedEnumerateNews()
 {
     Feed feed = new Feed("");
     feed.SetContent(WellFormedRss);
     INews[] news = feed.GetNews().ToArray();
     Assert.AreEqual(40, news.Length);
     Assert.AreEqual("http://g1.globo.com/sp/presidente-prudente-regiao/noticia/2015/03/pres-prudente-tem-59-oportunidades-de-trabalho-pelo-emprega-sao-paulo.html", news[0].Address);
     Assert.AreEqual("http://g1.globo.com/am/amazonas/noticia/2015/03/em-2-anos-mais-de-40-mil-casos-de-desvio-de-agua-sao-registrados-no-am.html", news[39].Address);
 }
        public static void Main()
        {
            var test = new DownloadSpeedTest();

            var cases = new [] {
                new TestCase {
                    TestName = "Download Client",
                    DownloadFunction = addrs =>
                        Parallel.ForEach(addrs,
                            addr => new DownloadClient(addr)
                                         .Download())
                },
                new TestCase {
                    TestName = "Download Request",
                    DownloadFunction = addrs =>
                        Parallel.ForEach(addrs,
                            addr => new DownloadRequest(addr)
                                         .Download())
                },
                new TestCase {
                    TestName = "Async Download Request",
                    DownloadFunction = addrs => {
                        var reqs = addrs.Select(addr => new AsyncDownloadRequest(addr));
                        foreach(var req in reqs) {
                            req.BeginDownloadingData();
                        }
                        foreach(var req in reqs) {
                            req.WaitUntilDownloadFinishes();
                        }
                    }
                }
            };

            var assembly = Assembly.GetExecutingAssembly();
            var wellFormedRss = assembly.GetEmbeddedFileText("RssExtractor.Tests", "TestData/WellFormedRss.xml");
            var feed = new Feed("");
            feed.SetContent(wellFormedRss);
            var news = feed.GetNews().ToArray();

            test.Run(cases, news.Select(n => n.Address).ToArray());
        }