Summary description for RSSWriter
Exemple #1
0
    protected void WriteRSSFile()
    {
        try
        {
            string fileName = links.RssFeedLink.Replace(@"~\", ""); ;
            string filePath = HttpRuntime.AppDomainAppPath + fileName;

            XmlWriter xml = new XmlTextWriter(new StreamWriter(filePath));
            RssWriter rss = new RssWriter(xml);

            List<Item> itemList = engine.LoadItemDB(ProcessingEngine.Sort.Hot);

            rss.WriteHeader("getputs.com", "http://www.getputs.com", "All Your News Belong To Us!", null);

            foreach (Item item in itemList)
            {
                rss.WriteItem(item);
            }

            rss.Close();
            xml.Close();

        }
        catch (Exception ex)
        {
            if (log.isLoggingOn && log.isAppLoggingOn)
            {
                log.Log("Error in RssPage.aspx");
                log.Log(ex);
            }
        }
    }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime now = DateTime.Now;
        Organization org = Organization.FromIdentity(Int32.Parse(Request.QueryString["OrganizationId"]));

        ExternalActivities activities = ExternalActivities.ForOrganization(org);
        activities.Sort(ExternalActivities.SortOrder.DateDescending);

        Response.ContentType = "text/xml";

        XmlWriter xml = new XmlTextWriter(Response.Output);
        RssWriter rss = new RssWriter(xml);

        rss.WriteHeader("Aktivism - " + org.Name, "http://www.piratpartiet.se", "Aktivism för Piratpartiet", null);

        foreach (ExternalActivity activism in activities)
        {
            string title = "Aktivism i " + activism.Geography.Name;
            if (title.Length > 60)
            {
                title = title.Substring(0, 57) + "...";
            }

            rss.WriteItem(title, "<img src=\"http://data.piratpartiet.se/Handlers/DisplayActivism.aspx?Id=" + activism.Identity.ToString() + "\" />", new Uri("http://data.piratpartiet.se/Handlers/DisplayActivism.aspx?Id=" + activism.Identity), activism.CreatedDateTime);
        }

        rss.Close();
        xml.Close();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime now = DateTime.Now;

        MediaEntries entries = (MediaEntries) Cache.Get(cacheKey);

        if (entries == null)
        {
            entries = MediaEntries.FromBlogKeyword("Piratpartiet", now.AddDays(-7));
            Cache.Insert(cacheKey, entries, null, DateTime.UtcNow.AddMinutes (5) , System.Web.Caching.Cache.NoSlidingExpiration); // five minute cache is plenty to prevent db F5 attacks
        }
      
        Response.ContentType = "text/xml";

        XmlWriter xml = new XmlTextWriter(Response.Output);
        RssWriter rss = new RssWriter(xml);

        rss.WriteHeader("Bloggat om Piratpartiet", "http://www.piratpartiet.se", "Bloggposter som nämner Piratpartiet", null);

        foreach (MediaEntry entry in entries)
        {
            string title = entry.Title;
            if (title.Length > 30)
            {
                title = title.Substring(0, 27) + "...";
            }

            rss.WriteItem(title, string.Empty, new Uri (entry.Url), entry.DateTime);
        }

        rss.Close();
        xml.Close();
    }
Exemple #4
0
        public async Task <ActionResult> IndexAsync(string categoryAlias = "", int pageNumber = 1)
        {
            if (pageNumber <= 0)
            {
                pageNumber = 1;
            }

            var channel = await RssModel.GetRssChannelAsync(this.Tenant, FrapidHttpContext.GetCurrent(), categoryAlias, pageNumber).ConfigureAwait(false);

            string rss = RssWriter.Write(channel);

            return(this.Content(rss, "text/xml", Encoding.UTF8));
        }
Exemple #5
0
        public void RssImageUrlConcatenatedProperly(string application, string subfolder, string expected)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", subfolder, application);
            BlogInfo blogInfo = new BlogInfo();
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = subfolder;
            blogInfo.Title = "My Blog Is Better Than Yours";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            RssWriter writer = new RssWriter(new List<Entry>(), DateTime.Now, false);
            Uri rssImageUrl = writer.GetRssImage();
            Assert.AreEqual(expected, rssImageUrl.ToString(), "not the expected url.");
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";

            Manufacturer roland = new Manufacturer() { Id = 1, Name = "Roland" };
            Manufacturer fender = new Manufacturer() { Id = 2, Name = "Fender" };
            Manufacturer zoom = new Manufacturer() { Id = 3, Name = "Zoom" };

            Product juno = new Product()
            {
                Id = 1000,
                Description = "The Juno-D is the most competitively priced and full-featured synthesizer in its class. Hundreds of radio-ready sounds are packed into the Juno-D’s jet-black metal chassis, along with a world-class array of expressive multi-effects, realtime performance controllers, and tools for groove creation and composition. ",
                Name = "Juno D 61 Key Pro Keyboard",
                Manufacturer = roland,
                CreateDate = DateTime.Now
            };

            Product tele = new Product()
            {
                Id = 1001,
                Name = "American Series Telecaster Electric Guitar",
                Description = "Over the past five-plus decades, the Fender American Telecaster electric guitar has been through numerous design variations, but its heart and soul has remained the same. For the American Series Telecaster, the original body radius and new parchment-colored pickguard give you the classic feel with a distinctive look.",
                Manufacturer = fender,
                CreateDate = DateTime.Now.AddDays(-3)
            };

            Product h2 = new Product()
            {
                Id = 1003,
                Name = "H2 Handy Portable Digital Recorder",
                Description = "Who Needs the H2 Handy Recorder from Zoom? Everyone who craves brilliant stereo recording. Simplicity is a beautiful thing. It's a simple idea: provide brilliant stereo recording in an easy-to-use, ultra-portable device. Now everyone can record pristine audio in an infinite variety of applications. From seminars and conferences, to electronic news gathering (ENG) and podcasting, to musical performances, songwriting sessions and rehearsals, the H2 provides amazing recording quality. And no matter what kind of music you perform or the instrument you play, the H2 can effortlessly record it in high-quality stereo.",
                Manufacturer = zoom,
                CreateDate = DateTime.Now.AddDays(-1)
            };

            RssWriter<Product> writer = new RssWriter<Product>
                (
                    "Code Voyeur Music Product Listing",
                    "http://www.codevoyeurmusic.com",
                    "New Products",
                    new Product[] {juno, tele, h2}
                );
            context.Response.Write(writer.GetFeed());
        }
        public void RssImageUrlConcatenatedProperly(string application, string subfolder, string expected)
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", subfolder, application);
            var blogInfo = new Blog();
            BlogRequest.Current.Blog = blogInfo;
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = subfolder;
            blogInfo.Title = "My Blog Is Better Than Yours";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.FakeSyndicationContext(blogInfo, "/", application, null);
            Mock<HttpContextBase> httpContext = Mock.Get(subtextContext.Object.RequestContext.HttpContext);
            httpContext.Setup(h => h.Request.ApplicationPath).Returns(application);

            var writer = new RssWriter(new StringWriter(), new List<Entry>(), DateTime.Now, false, subtextContext.Object);
            Uri rssImageUrl = writer.GetRssImage();
            Assert.AreEqual(expected, rssImageUrl.ToString(), "not the expected url.");
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Rss rss = new Rss()
            {
                Channel = new RssChannel()
                {
                    Title       = "测试网站",
                    Link        = "www.测试网站.com",
                    Description = "网站描述",

                    Category  = "测试",
                    Copyright = "20XX  www.测试网站.com All rights reserved.",
                    Language  = "zh-cn",

                    PubDate       = DateTime.Now,
                    LastBuildDate = DateTime.Now,


                    Items = new RssChannelItem[3],
                },
            };

            for (int i = 0; i < 3; i++)
            {
                rss.Channel.Items[i] = new RssChannelItem()
                {
                    Title       = "文章" + i,
                    Link        = "www.测试网站.com/Doc/" + i,
                    Description = "文章描述.  <a href='#'> 链接信息 </a> ......  " + i,

                    PubDate = DateTime.Now,
                };
            }



            RssWriter writer = new RssWriter();

            writer.WriteRssFile(rss, "test.xml");
        }
Exemple #9
0
        public void RssWriterHandlesRFC3229DeltaEncoding()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            BlogInfo blogInfo = new BlogInfo();
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.TimeZoneId = PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            List<Entry> entries = new List<Entry>(CreateSomeEntriesDescending());
            // Tell the write we already received 1002 published 6/25/1976.
            RssWriter writer = new RssWriter(entries, DateTime.ParseExact("06/25/1976","MM/dd/yyyy",CultureInfo.InvariantCulture), true);

            // We only expect 1003 and 1004
            string expected = @"<rss version=""2.0"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" + Environment.NewLine
                                + indent() + "<channel>" + Environment.NewLine
                                    + indent(2) + "<title />" + Environment.NewLine
                                    + indent(2) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                    + indent(2) + "<description />" + Environment.NewLine
                                    + indent(2) + "<language>en-US</language>" + Environment.NewLine
                                    + indent(2) + "<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                                    + indent(2) + "<managingEditor>[email protected]</managingEditor>" + Environment.NewLine
                                    + indent(2) + "<generator>{0}</generator>" + Environment.NewLine
                                    + indent(2) + "<image>" + Environment.NewLine
                                        + indent(3) + "<title />" + Environment.NewLine
                                        + indent(3) + "<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                                        + indent(3) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                        + indent(3) + "<width>77</width>" + Environment.NewLine
                                        + indent(3) + "<height>60</height>" + Environment.NewLine
                                    + indent(2) + "</image>" + Environment.NewLine
                                    + indent(2) + @"<item>" + Environment.NewLine
                                        + indent(3) + @"<title>Title of 1004.</title>" + Environment.NewLine
                                        + indent(3) + @"<link>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</link>" + Environment.NewLine
                                        + indent(3) + @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                        + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                        + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</guid>" + Environment.NewLine
                                        + indent(3) + @"<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                                        + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx#feedback</comments>" + Environment.NewLine
                                        + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" + Environment.NewLine
                                    + indent(2) + @"</item>" + Environment.NewLine
                                    + indent(2) + @"<item>" + Environment.NewLine
                                        + indent(3) + "<title>Title of 1003.</title>" + Environment.NewLine
                                        + indent(3) + "<link>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</link>" + Environment.NewLine
                                        + indent(3) + @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                        + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                        + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</guid>" + Environment.NewLine
                                        + indent(3) + @"<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                                        + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx#feedback</comments>" + Environment.NewLine
                                        + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" + Environment.NewLine
                                    + indent(2) + "</item>" + Environment.NewLine
                                + indent() + "</channel>" + Environment.NewLine
                              + "</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);

            Assert.AreEqual(expected, writer.Xml);

            Assert.AreEqual(DateTime.ParseExact("06/25/1976","MM/dd/yyyy",CultureInfo.InvariantCulture), writer.DateLastViewedFeedItemPublished, "The Item ID Last Viewed (according to If-None-Since is wrong.");
            Assert.AreEqual(DateTime.ParseExact("07/14/2003","MM/dd/yyyy",CultureInfo.InvariantCulture), writer.LatestPublishDate, "The Latest Feed Item ID sent to the client is wrong.");
        }
Exemple #10
0
        public void RssWriterSendsWholeFeedWhenRFC3229Disabled()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            BlogInfo blogInfo = new BlogInfo();
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = false;
            blogInfo.TimeZoneId = PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            List<Entry> entries = new List<Entry>(CreateSomeEntriesDescending());
            RssWriter writer = new RssWriter(entries, DateTime.ParseExact("07/14/2003", "MM/dd/yyyy", CultureInfo.InvariantCulture), false);

            string expected = @"<rss version=""2.0"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" + Environment.NewLine
                                + indent() + "<channel>" + Environment.NewLine
                                    + indent(2) + "<title />" + Environment.NewLine
                                    + indent(2) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                    + indent(2) + "<description />" + Environment.NewLine
                                    + indent(2) + "<language>en-US</language>" + Environment.NewLine
                                    + indent(2) + "<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                                    + indent(2) + "<managingEditor>[email protected]</managingEditor>" + Environment.NewLine
                                    + indent(2) + "<generator>{0}</generator>" + Environment.NewLine
                                    + indent(2) + "<image>" + Environment.NewLine
                                        + indent(3) + "<title />" + Environment.NewLine
                                        + indent(3) + "<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                                        + indent(3) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                        + indent(3) + "<width>77</width>" + Environment.NewLine
                                        + indent(3) + "<height>60</height>" + Environment.NewLine
                                    + indent(2) + "</image>" + Environment.NewLine
                                    + indent(2) + @"<item>" + Environment.NewLine
                                        + indent(3) + "<title>Title of 1004.</title>" + Environment.NewLine
                                        + indent(3) + "<link>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</link>" + Environment.NewLine
                                        + indent(3) + @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                        + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                        + indent(3) + "<guid>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</guid>" + Environment.NewLine
                                        + indent(3) + "<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                                        + indent(3) + "<comments>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx#feedback</comments>" + Environment.NewLine
                                        + indent(3) + "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" + Environment.NewLine
                                    + indent(2) + "</item>" + Environment.NewLine
                                    + indent(2) + "<item>" + Environment.NewLine
                                        + indent(3) + "<title>Title of 1003.</title>" + Environment.NewLine
                                        + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</link>" + Environment.NewLine
                                        + indent(3) + @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                        + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                        + indent(3) + "<guid>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</guid>" + Environment.NewLine
                                        + indent(3) + "<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                                        + indent(3) + "<comments>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx#feedback</comments>" + Environment.NewLine
                                        + indent(3) + "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" + Environment.NewLine
                                    + indent(2) + "</item>" + Environment.NewLine
                                    + indent(2) + @"<item>" + Environment.NewLine
                                        + indent(3) + "<title>Title of 1002.</title>" + Environment.NewLine
                                        + indent(3) + "<link>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx</link>" + Environment.NewLine
                                        + indent(3) + @"<description>Body of 1002&lt;img src=""http://localhost/Subtext.Web/aggbug/1002.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                        + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                        + indent(3) + "<guid>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx</guid>" + Environment.NewLine
                                        + indent(3) + "<pubDate>Fri, 25 Jun 1976 07:00:00 GMT</pubDate>" + Environment.NewLine
                                        + indent(3) + "<comments>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx#feedback</comments>" + Environment.NewLine
                                        + indent(3) + "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1002.aspx</wfw:commentRss>" + Environment.NewLine
                                    + indent(2) + "</item>" + Environment.NewLine
                                    + indent(2) + @"<item>" + Environment.NewLine
                                        + indent(3) + "<title>Title of 1001.</title>" + Environment.NewLine
                                        + indent(3) + "<link>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx</link>" + Environment.NewLine
                                        + indent(3) + @"<description>Body of 1001&lt;img src=""http://localhost/Subtext.Web/aggbug/1001.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                        + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                        + indent(3) + "<guid>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx</guid>" + Environment.NewLine
                                        + indent(3) + "<pubDate>Sun, 23 Feb 1975 08:00:00 GMT</pubDate>" + Environment.NewLine
                                        + indent(3) + "<comments>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx#feedback</comments>" + Environment.NewLine
                                        + indent(3) + "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1001.aspx</wfw:commentRss>" + Environment.NewLine
                                    + indent(2) + "</item>" + Environment.NewLine
                                + indent() + "</channel>" + Environment.NewLine
                              + "</rss>";
            expected = string.Format(expected, VersionInfo.VersionDisplayText);
            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, writer.Xml);
        }
Exemple #11
0
        public void RssWriterProducesValidFeed()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            BlogInfo blogInfo = new BlogInfo();
            blogInfo.Host = "localhost";
            blogInfo.Title = "My Blog Is Better Than Yours";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.TimeZoneId = PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            List<Entry> entries = new List<Entry>(CreateSomeEntries());
            entries[0].Categories.AddRange(new string[] { "Category1", "Category2" });
            entries[0].Email = "*****@*****.**";
            entries[2].Categories.Add("Category 3");

            Enclosure enc = new Enclosure();

            enc.Url = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            enc.Title = "<Digital Photography Explained (for Geeks) with Aaron Hockley/>";
            enc.Size = 26707573;
            enc.MimeType = "audio/mp3";
            enc.AddToFeed = true;

            entries[2].Enclosure = enc;

            Enclosure enc1 = new Enclosure();

            enc1.Url = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            enc1.Title = "<Digital Photography Explained (for Geeks) with Aaron Hockley/>";
            enc1.Size = 26707573;
            enc1.MimeType = "audio/mp3";
            enc1.AddToFeed = false;

            entries[3].Enclosure = enc1;

            RssWriter writer = new RssWriter(entries, NullValue.NullDateTime, false);

            string expected = @"<rss version=""2.0"" "
                                    + @"xmlns:dc=""http://purl.org/dc/elements/1.1/"" "
                                    + @"xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" "
                                    + @"xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" "
                                    + @"xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" "
                                    + @"xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" "
                                    + @"xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" + Environment.NewLine
                                + indent() + @"<channel>" + Environment.NewLine
                                        + indent(2) + @"<title>My Blog Is Better Than Yours</title>" + Environment.NewLine
                                        + indent(2) + @"<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                        + indent(2) + @"<description />" + Environment.NewLine
                                        + indent(2) + @"<language>en-US</language>" + Environment.NewLine
                                        + indent(2) + @"<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                                        + indent(2) + @"<managingEditor>[email protected]</managingEditor>" + Environment.NewLine
                                        + indent(2) + @"<generator>{0}</generator>" + Environment.NewLine
                                        + indent(2) + @"<image>" + Environment.NewLine
                                            + indent(3) + @"<title>My Blog Is Better Than Yours</title>" + Environment.NewLine
                                            + indent(3) + @"<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<width>77</width>" + Environment.NewLine
                                            + indent(3) + @"<height>60</height>" + Environment.NewLine
                                        + indent(2) + @"</image>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1001.</title>" + Environment.NewLine
                                            + indent(3) + @"<category>Category1</category>" + Environment.NewLine
                                            + indent(3) + @"<category>Category2</category>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1001&lt;img src=""http://localhost/Subtext.Web/aggbug/1001.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Sun, 23 Feb 1975 08:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1975/02/23/1001.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1001.aspx</wfw:commentRss>" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1002.</title>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1002&lt;img src=""http://localhost/Subtext.Web/aggbug/1002.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Fri, 25 Jun 1976 07:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1976/06/25/1002.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1002.aspx</wfw:commentRss>" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1003.</title>" + Environment.NewLine
                                            + indent(3) + @"<category>Category 3</category>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/1979/10/16/1003.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" + Environment.NewLine
                                            + indent(3) + @"<enclosure url=""http://perseus.franklins.net/hanselminutes_0107.mp3"" length=""26707573"" type=""audio/mp3"" />" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                        + indent(2) + @"<item>" + Environment.NewLine
                                            + indent(3) + @"<title>Title of 1004.</title>" + Environment.NewLine
                                            + indent(3) + @"<link>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</link>" + Environment.NewLine
                                            + indent(3) + @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" + Environment.NewLine
                                            + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                                            + indent(3) + @"<guid>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx</guid>" + Environment.NewLine
                                            + indent(3) + @"<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                                            + indent(3) + @"<comments>http://localhost/Subtext.Web/archive/2003/07/14/1004.aspx#feedback</comments>" + Environment.NewLine
                                            + indent(3) + @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" + Environment.NewLine
                                        + indent(2) + @"</item>" + Environment.NewLine
                                + indent() + @"</channel>" + Environment.NewLine
                              + @"</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);

            Console.WriteLine(expected);
            Console.WriteLine(writer.Xml);
            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, writer.Xml);
        }
Exemple #12
0
        private void write(RssWriter writer)
        {
            try
            {
                if (channels.Count == 0)
                    throw new InvalidOperationException("Feed must contain at least one channel.");

                writer.Version = rssVersion;

                writer.Modules = modules;

                foreach (DSD.Site.UtilityClasses.RSS.NET.RssChannel.RssChannel channel in channels)
                {
                    if (channel.Items.Count == 0)
                        throw new InvalidOperationException("Channel must contain at least one item.");

                    writer.Write(channel);
                }
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }
Exemple #13
0
        public void RssWriterProducesValidFeed()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            var blogInfo = new Blog();

            BlogRequest.Current.Blog             = blogInfo;
            blogInfo.Host                        = "localhost";
            blogInfo.Title                       = "My Blog Is Better Than Yours";
            blogInfo.Email                       = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.TimeZoneId                  = TimeZonesTest.PacificTimeZoneId;
            blogInfo.ShowEmailAddressInRss       = true;
            blogInfo.TrackbacksEnabled           = true;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            var entries = new List <Entry>(CreateSomeEntries());

            entries[0].Categories.AddRange(new[] { "Category1", "Category2" });
            entries[0].Email = "*****@*****.**";
            entries[2].Categories.Add("Category 3");

            var enc = new Enclosure();

            enc.Url              = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            enc.Title            = "<Digital Photography Explained (for Geeks) with Aaron Hockley/>";
            enc.Size             = 26707573;
            enc.MimeType         = "audio/mp3";
            enc.AddToFeed        = true;
            entries[2].Enclosure = enc;

            var enc1 = new Enclosure();

            enc1.Url       = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            enc1.Title     = "<Digital Photography Explained (for Geeks) with Aaron Hockley/>";
            enc1.Size      = 26707573;
            enc1.MimeType  = "audio/mp3";
            enc1.AddToFeed = false;

            entries[3].Enclosure = enc1;

            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.FakeSyndicationContext(blogInfo, "/", "Subtext.Web", null);
            Mock <UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/Subtext.Web/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns <Entry>(
                e => "/Subtext.Web/whatever/" + e.Id + ".aspx");

            var writer = new RssWriter(new StringWriter(), entries, NullValue.NullDateTime, false, subtextContext.Object);

            string expected = @"<rss version=""2.0"" "
                              + @"xmlns:dc=""http://purl.org/dc/elements/1.1/"" "
                              + @"xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" "
                              + @"xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" "
                              + @"xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" "
                              + @"xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" "
                              + @"xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" + Environment.NewLine
                              + indent() + @"<channel>" + Environment.NewLine
                              + indent(2) + @"<title>My Blog Is Better Than Yours</title>" + Environment.NewLine
                              + indent(2) + @"<link>http://localhost/Subtext.Web/Default.aspx</link>" +
                              Environment.NewLine
                              + indent(2) + @"<description />" + Environment.NewLine
                              + indent(2) + @"<language>en-US</language>" + Environment.NewLine
                              + indent(2) + @"<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                              + indent(2) + @"<managingEditor>[email protected]</managingEditor>" +
                              Environment.NewLine
                              + indent(2) + @"<generator>{0}</generator>" + Environment.NewLine
                              + indent(2) + @"<image>" + Environment.NewLine
                              + indent(3) + @"<title>My Blog Is Better Than Yours</title>" + Environment.NewLine
                              + indent(3) + @"<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" +
                              Environment.NewLine
                              + indent(3) + @"<link>http://localhost/Subtext.Web/Default.aspx</link>" +
                              Environment.NewLine
                              + indent(3) + @"<width>77</width>" + Environment.NewLine
                              + indent(3) + @"<height>60</height>" + Environment.NewLine
                              + indent(2) + @"</image>" + Environment.NewLine
                              + indent(2) + @"<item>" + Environment.NewLine
                              + indent(3) + @"<title>Title of 1001.</title>" + Environment.NewLine
                              + indent(3) + @"<category>Category1</category>" + Environment.NewLine
                              + indent(3) + @"<category>Category2</category>" + Environment.NewLine
                              + indent(3) + @"<link>http://localhost/Subtext.Web/whatever/1001.aspx</link>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<description>Body of 1001&lt;img src=""http://localhost/Subtext.Web/aggbug/1001.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                              Environment.NewLine
                              + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                              + indent(3) + @"<guid>http://localhost/Subtext.Web/whatever/1001.aspx</guid>" +
                              Environment.NewLine
                              + indent(3) + @"<pubDate>Sun, 23 Feb 1975 08:00:00 GMT</pubDate>" + Environment.NewLine
                              + indent(3) +
                              @"<comments>http://localhost/Subtext.Web/whatever/1001.aspx#feedback</comments>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1001.aspx</wfw:commentRss>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<trackback:ping>http://localhost/Subtext.Web/services/trackbacks/1001.aspx</trackback:ping>" +
                              Environment.NewLine
                              + indent(2) + @"</item>" + Environment.NewLine
                              + indent(2) + @"<item>" + Environment.NewLine
                              + indent(3) + @"<title>Title of 1002.</title>" + Environment.NewLine
                              + indent(3) + @"<link>http://localhost/Subtext.Web/whatever/1002.aspx</link>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<description>Body of 1002&lt;img src=""http://localhost/Subtext.Web/aggbug/1002.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                              Environment.NewLine
                              + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                              + indent(3) + @"<guid>http://localhost/Subtext.Web/whatever/1002.aspx</guid>" +
                              Environment.NewLine
                              + indent(3) + @"<pubDate>Fri, 25 Jun 1976 07:00:00 GMT</pubDate>" + Environment.NewLine
                              + indent(3) +
                              @"<comments>http://localhost/Subtext.Web/whatever/1002.aspx#feedback</comments>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1002.aspx</wfw:commentRss>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<trackback:ping>http://localhost/Subtext.Web/services/trackbacks/1002.aspx</trackback:ping>" +
                              Environment.NewLine
                              + indent(2) + @"</item>" + Environment.NewLine
                              + indent(2) + @"<item>" + Environment.NewLine
                              + indent(3) + @"<title>Title of 1003.</title>" + Environment.NewLine
                              + indent(3) + @"<category>Category 3</category>" + Environment.NewLine
                              + indent(3) + @"<link>http://localhost/Subtext.Web/whatever/1003.aspx</link>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                              Environment.NewLine
                              + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                              + indent(3) + @"<guid>http://localhost/Subtext.Web/whatever/1003.aspx</guid>" +
                              Environment.NewLine
                              + indent(3) + @"<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                              + indent(3) +
                              @"<comments>http://localhost/Subtext.Web/whatever/1003.aspx#feedback</comments>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<trackback:ping>http://localhost/Subtext.Web/services/trackbacks/1003.aspx</trackback:ping>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<enclosure url=""http://perseus.franklins.net/hanselminutes_0107.mp3"" length=""26707573"" type=""audio/mp3"" />" +
                              Environment.NewLine
                              + indent(2) + @"</item>" + Environment.NewLine
                              + indent(2) + @"<item>" + Environment.NewLine
                              + indent(3) + @"<title>Title of 1004.</title>" + Environment.NewLine
                              + indent(3) + @"<link>http://localhost/Subtext.Web/whatever/1004.aspx</link>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                              Environment.NewLine
                              + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                              + indent(3) + @"<guid>http://localhost/Subtext.Web/whatever/1004.aspx</guid>" +
                              Environment.NewLine
                              + indent(3) + @"<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                              + indent(3) +
                              @"<comments>http://localhost/Subtext.Web/whatever/1004.aspx#feedback</comments>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<trackback:ping>http://localhost/Subtext.Web/services/trackbacks/1004.aspx</trackback:ping>" +
                              Environment.NewLine
                              + indent(2) + @"</item>" + Environment.NewLine
                              + indent() + @"</channel>" + Environment.NewLine
                              + @"</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);

            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, writer.Xml);
        }
Exemple #14
0
        public void RssWriterHandlesRFC3229DeltaEncoding()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            var blogInfo = new Blog();

            BlogRequest.Current.Blog             = blogInfo;
            blogInfo.Host                        = "localhost";
            blogInfo.Subfolder                   = "";
            blogInfo.Email                       = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.TimeZoneId                  = TimeZonesTest.PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            var entries        = new List <Entry>(CreateSomeEntriesDescending());
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.FakeSyndicationContext(blogInfo, "/", "Subtext.Web", null);
            Mock <UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/Subtext.Web/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/Subtext.Web/whatever");

            // Tell the write we already received 1002 published 6/25/1976.
            var writer = new RssWriter(new StringWriter(), entries,
                                       DateTime.ParseExact("06/25/1976", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                       true, subtextContext.Object);

            // We only expect 1003 and 1004
            string expected =
                @"<rss version=""2.0"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" +
                Environment.NewLine
                + indent() + "<channel>" + Environment.NewLine
                + indent(2) + "<title />" + Environment.NewLine
                + indent(2) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                + indent(2) + "<description />" + Environment.NewLine
                + indent(2) + "<language>en-US</language>" + Environment.NewLine
                + indent(2) + "<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                + indent(2) + "<generator>{0}</generator>" + Environment.NewLine
                + indent(2) + "<image>" + Environment.NewLine
                + indent(3) + "<title />" + Environment.NewLine
                + indent(3) + "<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                + indent(3) + "<width>77</width>" + Environment.NewLine
                + indent(3) + "<height>60</height>" + Environment.NewLine
                + indent(2) + "</image>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + @"<title>Title of 1004.</title>" + Environment.NewLine
                + indent(3) + @"<link>http://localhost/Subtext.Web/whatever</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + @"<guid>http://localhost/Subtext.Web/whatever</guid>" + Environment.NewLine
                + indent(3) + @"<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + @"<comments>http://localhost/Subtext.Web/whatever#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + @"</item>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1003.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + @"<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + @"<guid>http://localhost/Subtext.Web/whatever</guid>" + Environment.NewLine
                + indent(3) + @"<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + @"<comments>http://localhost/Subtext.Web/whatever#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                @"<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent() + "</channel>" + Environment.NewLine
                + "</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);

            Assert.AreEqual(expected, writer.Xml);

            Assert.AreEqual(DateTime.ParseExact("06/25/1976", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                            writer.DateLastViewedFeedItemPublished,
                            "The Item ID Last Viewed (according to If-None-Since is wrong.");
            Assert.AreEqual(DateTime.ParseExact("07/14/2003", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                            writer.LatestPublishDate, "The Latest Feed Item ID sent to the client is wrong.");
        }
        public void RssWriterSendsWholeFeedWhenRFC3229Disabled()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            var blogInfo = new Blog();
            BlogRequest.Current.Blog = blogInfo;
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "";
            blogInfo.Email = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = false;
            blogInfo.TimeZoneId = TimeZonesTest.PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            var entries = new List<Entry>(CreateSomeEntriesDescending());
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.FakeSyndicationContext(blogInfo, "/Subtext.Web/", "Subtext.Web", null);
            Mock<UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/Subtext.Web/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns<Entry>(e => "/Subtext.Web/whatever/" + e.Id);

            var writer = new RssWriter(new StringWriter(), entries,
                                       DateTime.ParseExact("07/14/2003", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                       false, subtextContext.Object);

            string expected =
                @"<rss version=""2.0"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" +
                Environment.NewLine
                + indent() + "<channel>" + Environment.NewLine
                + indent(2) + "<title />" + Environment.NewLine
                + indent(2) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                + indent(2) + "<description />" + Environment.NewLine
                + indent(2) + "<language>en-US</language>" + Environment.NewLine
                + indent(2) + "<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                + indent(2) + "<generator>{0}</generator>" + Environment.NewLine
                + indent(2) + "<image>" + Environment.NewLine
                + indent(3) + "<title />" + Environment.NewLine
                + indent(3) + "<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                + indent(3) + "<width>77</width>" + Environment.NewLine
                + indent(3) + "<height>60</height>" + Environment.NewLine
                + indent(2) + "</image>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1004.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever/1004</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1004</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1004#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent(2) + "<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1003.</title>" + Environment.NewLine
                + indent(3) + @"<link>http://localhost/Subtext.Web/whatever/1003</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1003</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1003#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1002.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever/1002</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1002&lt;img src=""http://localhost/Subtext.Web/aggbug/1002.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1002</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Fri, 25 Jun 1976 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1002#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1002.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1001.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever/1001</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1001&lt;img src=""http://localhost/Subtext.Web/aggbug/1001.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1001</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Sun, 23 Feb 1975 08:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1001#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1001.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent() + "</channel>" + Environment.NewLine
                + "</rss>";
            expected = string.Format(expected, VersionInfo.VersionDisplayText);
            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, writer.Xml);
        }
Exemple #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rssFeed"></param>
        /// <returns></returns>
        public string Write(RssFeed rssFeed)
        {
            var writer = RssWriter.Create(rssFeed.Version);

            return(writer.Write(rssFeed));
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";

            Manufacturer roland = new Manufacturer() { Id = 1, Name = "Roland" };
            Manufacturer fender = new Manufacturer() { Id = 2, Name = "Fender" };
            Manufacturer zoom = new Manufacturer() { Id = 3, Name = "Zoom" };

            Product juno = new Product()
            {
                Id = 1000,
                Description = "he Juno-D is the most competitively priced and full-featured synthesizer in its class. Hundreds of radio-ready sounds are packed into the Juno-D’s jet-black metal chassis, along with a world-class array of expressive multi-effects, realtime performance controllers, and tools for groove creation and composition. ",
                Name = "Juno D 61 Key Pro Keyboard",
                Manufacturer = roland,
                CreateDate = DateTime.Now
            };

            Product tele = new Product()
            {
                Id = 1001,
                Name = "American Series Telecaster Electric Guitar",
                Description = "Over the past five-plus decades, the Fender American Telecaster electric guitar has been through numerous design variations, but its heart and soul has remained the same. For the American Series Telecaster, the original body radius and new parchment-colored pickguard give you the classic feel with a distinctive look.",
                Manufacturer = fender,
                CreateDate = DateTime.Now.AddDays(-3)
            };

            Product h2 = new Product()
            {
                Id = 1003,
                Name = "H2 Handy Portable Digital Recorder",
                Description = "Who Needs the H2 Handy Recorder from Zoom? Everyone who craves brilliant stereo recording. Simplicity is a beautiful thing. It's a simple idea: provide brilliant stereo recording in an easy-to-use, ultra-portable device. Now everyone can record pristine audio in an infinite variety of applications. From seminars and conferences, to electronic news gathering (ENG) and podcasting, to musical performances, songwriting sessions and rehearsals, the H2 provides amazing recording quality. And no matter what kind of music you perform or the instrument you play, the H2 can effortlessly record it in high-quality stereo.",
                Manufacturer = zoom,
                CreateDate = DateTime.Now.AddDays(-1)
            };

            ProductReview h2Review = new ProductReview()
            {
                Id = 10,
                Product = h2,
                Review = "After tantalizing hints and a more tantalizing shipping delay, the Zoom H2 is finally here, promising digital surround-sound recording in the palm of your hand for only $199. Was it worth the wait? Well, let me say that it certainly lives up to its moniker: this is one Handy Recorder.",
                ReviewDate = DateTime.Now,
                UserName = "******"
            };

            ProductReview teleReview = new ProductReview()
            {
                Id = 10,
                Product = tele,
                Review = "Not a single flaw to be found. Neck is wonderful, and paly like no guitar I have picked up before. Stock setup, well it's a Fender.",
                ReviewDate = DateTime.Now,
                UserName = "******"
            };

            ProductReview junoReview = new ProductReview()
            {
                Id = 10,
                Product = juno,
                Review = "The first thing you notice when turning it on is the screen. It's much bigger than it looks in the pictures on Roland's site; very bright and very orange. Similar to the look of the XP-50 screen, but bigger text and a lot more information. The contrast knob has a wide range and makes the screen viewable from any angle.",
                ReviewDate = DateTime.Now,
                UserName = "******"
            };

            RssWriter<ProductReview> writer = new RssWriter<ProductReview>
                (
                    "Code Voyeur Music Product Reviews",
                    "http://www.codevoyeurmusic.com/reviews",
                    "Recent Product Reviews",
                    new ProductReview[] { junoReview, teleReview, h2Review }
                );
            context.Response.Write(writer.GetFeed());
        }
Exemple #18
0
 /// <summary>Writes the RSS feed to the specified file.</summary>
 /// <remarks>The encoding is ISO-8859-1.</remarks>
 /// <exception cref="ArgumentException">The filename is empty, contains only white space, or contains one or more invalid characters.</exception>
 /// <exception cref="UnauthorizedAccessException">Access is denied.</exception>
 /// <exception cref="ArgumentNullException">The filename is a (null c#, Nothing vb) reference.</exception>
 /// <exception cref="DirectoryNotFoundException">The directory to write to is not found.</exception>
 /// <exception cref="IOException">The filename includes an incorrect or invalid syntax for file name, directory name, or volume label syntax.</exception>
 /// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
 /// <param name="fileName">specified file (including path) If the file exists, it will be truncated with the new content.</param>
 /// <exception cref="InvalidOperationException">Feed must contain at least one channel.</exception>
 /// <exception cref="InvalidOperationException">Channel must contain at least one item.</exception>
 public void Write(string fileName)
 {
     RssWriter writer = new RssWriter(fileName);
     write(writer);
 }
Exemple #19
0
        /// <summary>Writes the RSS feed to the specified stream.</summary>
        /// <param name="stream">specified Stream</param>
        /// <exception cref="ArgumentException">The Stream cannot be written to.</exception>
        /// <exception cref="InvalidOperationException">Feed must contain at least one channel.</exception>
        /// <exception cref="InvalidOperationException">Channel must contain at least one item.</exception>
        public void Write(Stream stream)
        {
            RssWriter writer;

            if (encoding == null)
                writer = new RssWriter(stream);
            else
                writer = new RssWriter(stream, encoding);
            write(writer);
        }
Exemple #20
0
        public void RssWriterSendsWholeFeedWhenRFC3229Disabled()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            var blogInfo = new Blog();

            BlogRequest.Current.Blog             = blogInfo;
            blogInfo.Host                        = "localhost";
            blogInfo.Subfolder                   = "";
            blogInfo.Email                       = "*****@*****.**";
            blogInfo.RFC3229DeltaEncodingEnabled = false;
            blogInfo.TimeZoneId                  = TimeZonesTest.PacificTimeZoneId;

            HttpContext.Current.Items.Add("BlogInfo-", blogInfo);

            var entries        = new List <Entry>(CreateSomeEntriesDescending());
            var subtextContext = new Mock <ISubtextContext>();

            subtextContext.FakeSyndicationContext(blogInfo, "/Subtext.Web/", "Subtext.Web", null);
            Mock <UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/Subtext.Web/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns <Entry>(e => "/Subtext.Web/whatever/" + e.Id);

            var writer = new RssWriter(new StringWriter(), entries,
                                       DateTime.ParseExact("07/14/2003", "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                       false, subtextContext.Object);

            string expected =
                @"<rss version=""2.0"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:trackback=""http://madskills.com/public/xml/rss/module/trackback/"" xmlns:wfw=""http://wellformedweb.org/CommentAPI/"" xmlns:slash=""http://purl.org/rss/1.0/modules/slash/"" xmlns:copyright=""http://blogs.law.harvard.edu/tech/rss"" xmlns:image=""http://purl.org/rss/1.0/modules/image/"">" +
                Environment.NewLine
                + indent() + "<channel>" + Environment.NewLine
                + indent(2) + "<title />" + Environment.NewLine
                + indent(2) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                + indent(2) + "<description />" + Environment.NewLine
                + indent(2) + "<language>en-US</language>" + Environment.NewLine
                + indent(2) + "<copyright>Subtext Weblog</copyright>" + Environment.NewLine
                + indent(2) + "<generator>{0}</generator>" + Environment.NewLine
                + indent(2) + "<image>" + Environment.NewLine
                + indent(3) + "<title />" + Environment.NewLine
                + indent(3) + "<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/Default.aspx</link>" + Environment.NewLine
                + indent(3) + "<width>77</width>" + Environment.NewLine
                + indent(3) + "<height>60</height>" + Environment.NewLine
                + indent(2) + "</image>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1004.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever/1004</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1004&lt;img src=""http://localhost/Subtext.Web/aggbug/1004.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1004</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Mon, 14 Jul 2003 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1004#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1004.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent(2) + "<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1003.</title>" + Environment.NewLine
                + indent(3) + @"<link>http://localhost/Subtext.Web/whatever/1003</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1003&lt;img src=""http://localhost/Subtext.Web/aggbug/1003.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1003</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Tue, 16 Oct 1979 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1003#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1003.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1002.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever/1002</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1002&lt;img src=""http://localhost/Subtext.Web/aggbug/1002.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1002</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Fri, 25 Jun 1976 07:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1002#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1002.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent(2) + @"<item>" + Environment.NewLine
                + indent(3) + "<title>Title of 1001.</title>" + Environment.NewLine
                + indent(3) + "<link>http://localhost/Subtext.Web/whatever/1001</link>" + Environment.NewLine
                + indent(3) +
                @"<description>Body of 1001&lt;img src=""http://localhost/Subtext.Web/aggbug/1001.aspx"" width=""1"" height=""1"" /&gt;</description>" +
                Environment.NewLine
                + indent(3) + "<dc:creator>Phil Haack</dc:creator>" + Environment.NewLine
                + indent(3) + "<guid>http://localhost/Subtext.Web/whatever/1001</guid>" + Environment.NewLine
                + indent(3) + "<pubDate>Sun, 23 Feb 1975 08:00:00 GMT</pubDate>" + Environment.NewLine
                + indent(3) + "<comments>http://localhost/Subtext.Web/whatever/1001#feedback</comments>" +
                Environment.NewLine
                + indent(3) +
                "<wfw:commentRss>http://localhost/Subtext.Web/comments/commentRss/1001.aspx</wfw:commentRss>" +
                Environment.NewLine
                + indent(2) + "</item>" + Environment.NewLine
                + indent() + "</channel>" + Environment.NewLine
                + "</rss>";

            expected = string.Format(expected, VersionInfo.VersionDisplayText);
            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, writer.Xml);
        }