コード例 #1
0
        public void RegressionTestUrlRelocationCheck()
        {
            int max_num = 1000;

            Console.WriteLine("Regression Test to check if url relocation works.");
            int wait = 0;
            List <UrlRelocationCheck> urc_list = new List <UrlRelocationCheck>();

            for (int i = 0; i < max_num; i++)
            {
                UrlRelocationCheck urc = new UrlRelocationCheck("http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/sn/SN-078.mp3");
                urc.FoundRelocatedUrl += delegate(UrlRelocationCheck urc_found)
                {
                    Console.WriteLine("");
                    Assert.IsTrue(urc_found.RelocatedUrl == "http://aolradio.podcast.aol.com/sn/SN-078.mp3", "wrong relocation url found.");
                    wait++;
                    Console.WriteLine("Url Relocation Check " + wait + " of " + max_num + " Completed (" + urc_found.RelocatedUrl + ")");

                    /*if (urc_found.Url != urc_found.RelocatedUrl)
                     * {
                     *  urc_found.Url = urc_found.RelocatedUrl;
                     *  urc_found.MimeType = "";
                     *  urc_found.RelocatedUrl = "";
                     *  urc_found.CheckUrl();
                     * }*/
                };
                urc_list.Add(urc);
            }
            for (int i = 0; i < max_num; i++)
            {
                urc_list[i].CheckUrl();
            }
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;

            while (wait < max_num)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, max_num / 4))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long -> " + wait + " of " + max_num + " tests (running attempts: " + UrlRelocationCheck.Attempts + " still in queue: " + UrlRelocationCheck.Queue.Count + ")completed");
                    wait = max_num;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                System.Threading.Thread.Sleep(250);
            }
            Assert.IsTrue(UrlRelocationCheck.Queue.Count == 0, "queue still containing entries.");
            Assert.IsTrue(UrlRelocationCheck.Attempts == 0, "attempts still running.");
            Console.WriteLine("Url Relocation Check Regression Test successful.");
        }
コード例 #2
0
        public void TestUrlRelocationCheckWrongUrl()
        {
            Console.WriteLine("Test to check if url relocation works with a wrong url.");
            bool wait = true;
            UrlRelocationCheck urc = new UrlRelocationCheck("http://www.podt.cmpt/SN-078.mp3");

            urc.FoundRelocatedUrl += delegate(UrlRelocationCheck urc_found)
            {
                Console.WriteLine("");
                Console.WriteLine("Url Relocation Check Completed (" + urc_found.RelocatedUrl + ")");

                /*if (urc_found.Url != urc_found.RelocatedUrl)
                 * {
                 *  urc_found.Url = urc_found.RelocatedUrl;
                 *  urc_found.MimeType = "";
                 *  urc_found.RelocatedUrl = "";
                 *  urc_found.CheckUrl();
                 * }*/
                //Assert.IsTrue(urc_found.RelocatedUrl == "http://aolradio.podcast.aol.com/sn/SN-078.mp3", "wrong relocation url found.");
                //wait = false;
            };
            urc.UrlNotFound += delegate(UrlRelocationCheck urc_not_found)
            {
                Console.WriteLine("");
                Console.WriteLine("Url Not Found check completed (" + urc_not_found.Url + ")");
                wait = false;
            };
            urc.CheckUrl();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;

            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 10))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                System.Threading.Thread.Sleep(250);
            }
            Console.WriteLine("running attempts: " + UrlRelocationCheck.Attempts + " still in queue: " + UrlRelocationCheck.Queue.Count);
            Assert.IsTrue(UrlRelocationCheck.Queue.Count == 0, "queue still containing entries.");
            Assert.IsTrue(UrlRelocationCheck.Attempts == 0, "attempts still running.");
            Console.WriteLine("Wrong Url Relocation Check Test successful.");
        }
コード例 #3
0
        private void ReadItem(XmlNode node, Channel channel)
        {
            Channel.Item item = new Channel.Item();
            if (node.HasChildNodes)
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.Title = child.InnerText;
                    }
                    if (child.Name.Equals("link", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.Link = child.InnerText;
                    }
                    if (child.Name.Equals("description", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.Description = XmlStrings.FromXmlString(child.InnerText);
                    }
                    if (child.Name.Equals("author", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.Author = child.InnerText;
                    }
                    if (child.Name.Equals("category", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.Categories.Add(child.InnerText);
                    }
                    if (child.Name.Equals("comments", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.Comments = child.InnerText;
                    }
                    if (child.Name.Equals("enclosure", StringComparison.CurrentCultureIgnoreCase))
                    {
                        Channel.Item.RssEnclosure enclosure = new Channel.Item.RssEnclosure();
                        foreach (XmlAttribute attr in child.Attributes)
                        {
                            if (attr.Name.Equals("url", StringComparison.CurrentCultureIgnoreCase))
                            {
                                enclosure.Url = attr.Value;
                                if (auto_relocation_check)
                                {//TODO check if this gets into gc soon after using it
                                    UrlRelocationCheck urc = new UrlRelocationCheck(enclosure.Url);
                                    urc.FoundRelocatedUrl += delegate(UrlRelocationCheck found_urc)
                                    {
                                        enclosure.Url = found_urc.RelocatedUrl;

                                        //found_urc.Url = found_urc.RelocatedUrl;
                                        //found_urc.MimeType = "";
                                        //found_urc.RelocatedUrl = "";
                                        //found_urc.CheckUrl();
                                    };
                                    urc.CheckUrl();
                                }
                            }

                            try
                            {
                                if (attr.Name.Equals("length", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    enclosure.Length = int.Parse(attr.Value);
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("error parsing enclosure length: " + ex.Message);
                            }
                            if (attr.Name.Equals("type", StringComparison.CurrentCultureIgnoreCase))
                            {
                                enclosure.ContentType = attr.Value;
                            }
                        }
                        item.Enclosure = enclosure;
                    }
                    if (child.Name.Equals("source", StringComparison.CurrentCultureIgnoreCase))
                    {
                        Channel.Item.TitledUrl source = new Channel.Item.TitledUrl();
                        foreach (XmlAttribute attr in child.Attributes)
                        {
                            if (attr.Name.Equals("url", StringComparison.CurrentCultureIgnoreCase))
                            {
                                source.Url = attr.Value;
                            }
                        }
                        source.Title = child.InnerText;
                        item.Source  = source;
                    }
                    if (child.Name.Equals("guid", StringComparison.CurrentCultureIgnoreCase))
                    {
                        item.GUID = child.InnerText;
                    }
                    try
                    {
                        //if (child.Name.Equals("pubDate")) channel.PubDate = DateTime.ParseExact(child.InnerText, "ddd, dd MMM yyyy HH:mm:ss zzz", null);
                        //channel.PubDate = Convert.ToDateTime(child.InnerText);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("error parsing item pubDate(" + child.InnerText + "): " + ex.Message);
                    }
                }
            }
            channel.Items.Add(item);
        }
コード例 #4
0
 public void TestUrlRelocationCheckWrongUrl()
 {
     Console.WriteLine("Test to check if url relocation works with a wrong url.");
     bool wait = true;
     UrlRelocationCheck urc = new UrlRelocationCheck("http://www.podt.cmpt/SN-078.mp3");
     urc.FoundRelocatedUrl += delegate(UrlRelocationCheck urc_found)
     {
         Console.WriteLine("");
         Console.WriteLine("Url Relocation Check Completed (" + urc_found.RelocatedUrl + ")");
         /*if (urc_found.Url != urc_found.RelocatedUrl)
         {
             urc_found.Url = urc_found.RelocatedUrl;
             urc_found.MimeType = "";
             urc_found.RelocatedUrl = "";
             urc_found.CheckUrl();
         }*/
         //Assert.IsTrue(urc_found.RelocatedUrl == "http://aolradio.podcast.aol.com/sn/SN-078.mp3", "wrong relocation url found.");
         //wait = false;
     };
     urc.UrlNotFound += delegate(UrlRelocationCheck urc_not_found)
     {
         Console.WriteLine("");
         Console.WriteLine("Url Not Found check completed (" + urc_not_found.Url + ")");
         wait = false;
     };
     urc.CheckUrl();
     Console.WriteLine("Waiting for data");
     DateTime start = DateTime.Now;
     while (wait)
     {
         if (DateTime.Now - start > new TimeSpan(0, 0, 10))
         {
             Console.WriteLine("");
             Console.WriteLine("Operation took too long");
             wait = false;
             Assert.Fail("Operation took too long");
         }
         Console.Write(".");
         System.Threading.Thread.Sleep(250);
     }
     Console.WriteLine("running attempts: " + UrlRelocationCheck.Attempts + " still in queue: " + UrlRelocationCheck.Queue.Count);
     Assert.IsTrue(UrlRelocationCheck.Queue.Count == 0, "queue still containing entries.");
     Assert.IsTrue(UrlRelocationCheck.Attempts == 0, "attempts still running.");
     Console.WriteLine("Wrong Url Relocation Check Test successful.");
 }
コード例 #5
0
 public void RegressionTestUrlRelocationCheck()
 {
     int max_num = 1000;
     Console.WriteLine("Regression Test to check if url relocation works.");
     int wait = 0;
     List<UrlRelocationCheck> urc_list = new List<UrlRelocationCheck>();
     for (int i = 0; i < max_num; i++)
     {
         UrlRelocationCheck urc = new UrlRelocationCheck("http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/sn/SN-078.mp3");
         urc.FoundRelocatedUrl += delegate(UrlRelocationCheck urc_found)
         {
             Console.WriteLine("");
             Assert.IsTrue(urc_found.RelocatedUrl == "http://aolradio.podcast.aol.com/sn/SN-078.mp3", "wrong relocation url found.");
             wait++;
             Console.WriteLine("Url Relocation Check " + wait + " of " + max_num + " Completed (" + urc_found.RelocatedUrl + ")");
             /*if (urc_found.Url != urc_found.RelocatedUrl)
             {
                 urc_found.Url = urc_found.RelocatedUrl;
                 urc_found.MimeType = "";
                 urc_found.RelocatedUrl = "";
                 urc_found.CheckUrl();
             }*/
         };
         urc_list.Add(urc);
     }
     for (int i = 0; i < max_num; i++)
     {
         urc_list[i].CheckUrl();
     }
     Console.WriteLine("Waiting for data");
     DateTime start = DateTime.Now;
     while (wait < max_num)
     {
         if (DateTime.Now - start > new TimeSpan(0, 0, max_num / 4))
         {
             Console.WriteLine("");
             Console.WriteLine("Operation took too long -> " + wait + " of " + max_num + " tests (running attempts: " + UrlRelocationCheck.Attempts + " still in queue: " + UrlRelocationCheck.Queue.Count + ")completed");
             wait = max_num;
             Assert.Fail("Operation took too long");
         }
         Console.Write(".");
         System.Threading.Thread.Sleep(250);
     }
     Assert.IsTrue(UrlRelocationCheck.Queue.Count == 0, "queue still containing entries.");
     Assert.IsTrue(UrlRelocationCheck.Attempts == 0, "attempts still running.");
     Console.WriteLine("Url Relocation Check Regression Test successful.");
 }