当前位置: 首页>>代码示例>>C#>>正文


C# Mock.FakeSyndicationContext方法代码示例

本文整理汇总了C#中Mock.FakeSyndicationContext方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.FakeSyndicationContext方法的具体用法?C# Mock.FakeSyndicationContext怎么用?C# Mock.FakeSyndicationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.FakeSyndicationContext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RssHandlerHandlesDatePublishedUtcProperly

        public void RssHandlerHandlesDatePublishedUtcProperly()
        {
            // arrange
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            var repository = new DatabaseObjectProvider();
            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            repository.CreateBlog("", "username", "password", hostName, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty);

            //Create two entries, but only include one in main syndication.
            Entry entryForSyndication = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test",
                                                                                         "Body Rocking");
            UnitTestHelper.Create(entryForSyndication);
            Entry entryTwoForSyndication = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2",
                                                                                            "Body Rocking Pt 2");
            int id = UnitTestHelper.Create(entryTwoForSyndication);
            Entry entry = UnitTestHelper.GetEntry(id, PostConfig.None, false);
            DateTime date = entry.DatePublishedUtc;
            entry.IncludeInMainSyndication = false;
            entry.Blog = new Blog() { Title = "MyTestBlog" };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            UnitTestHelper.Update(entry, subtextContext.Object);
            Assert.AreEqual(date, entry.DatePublishedUtc);

            string rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(1, itemNodes.Count, "expected one item node.");

            Assert.AreEqual("Title Test", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the first title.");
            Assert.AreEqual("Body Rocking",
                            itemNodes[0].SelectSingleNode("description").InnerText.Substring(0, "Body Rocking".Length),
                            "Not what we expected for the first body.");

            //Include the second entry back in the syndication.
            entry.IncludeInMainSyndication = true;
            UnitTestHelper.Update(entry, subtextContext.Object);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "", "");
            BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty);
            subtextContext = new Mock<ISubtextContext>();
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(2, itemNodes.Count, "Expected two items in the feed now.");
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:57,代码来源:RssHandlerTests.cs

示例2: CommentRssWriterProducesValidEmptyFeed

        public void CommentRssWriterProducesValidEmptyFeed()
        {
            var blogInfo = new Blog();
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "blog";
            blogInfo.Email = "[email protected]";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.Title = "My Blog Rulz";
            blogInfo.TimeZoneId = TimeZonesTest.PacificTimeZoneId;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication(blogInfo, "haacked", "title of the post",
                                                                           "Body of the post.");
            entry.EntryName = "titleofthepost";
            entry.DateCreatedUtc =
                entry.DatePublishedUtc =
                entry.DateModifiedUtc = DateTime.ParseExact("2006/04/01", "yyyy/MM/dd", CultureInfo.InvariantCulture);

            var context = new Mock<ISubtextContext>();
            context.FakeSyndicationContext(blogInfo, "/", null);
            Mock<BlogUrlHelper> urlHelper = Mock.Get(context.Object.UrlHelper);
            urlHelper.Setup(url => url.EntryUrl(It.IsAny<Entry>())).Returns(
                "/blog/archive/2006/04/01/titleofthepost.aspx");

            var writer = new CommentRssWriter(new StringWriter(), new List<FeedbackItem>(), entry, context.Object);

            Assert.IsTrue(entry.HasEntryName, "This entry should have an entry name.");

            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>title of the post</title>" + Environment.NewLine
                              + indent(2) + @"<link>http://localhost/blog/archive/2006/04/01/titleofthepost.aspx</link>" +
                              Environment.NewLine
                              + indent(2) + @"<description>Body of the post.</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>title of the post</title>" + Environment.NewLine
                              + indent(3) + @"<url>http://localhost/images/RSS2Image.gif</url>" + Environment.NewLine
                              + indent(3) + @"<link>http://localhost/blog/archive/2006/04/01/titleofthepost.aspx</link>" +
                              Environment.NewLine
                              + indent(3) + @"<width>77</width>" + Environment.NewLine
                              + indent(3) + @"<height>60</height>" + Environment.NewLine
                              + indent(2) + @"</image>" + Environment.NewLine
                              + indent(1) + @"</channel>" + Environment.NewLine
                              + @"</rss>";

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

            Assert.AreEqual(expected, writer.Xml);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:57,代码来源:CommentRssWriterTests.cs

示例3: AtomWriterProducesValidFeedFromDatabase

        public void AtomWriterProducesValidFeedFromDatabase()
        {
            string hostName = UnitTestHelper.GenerateUniqueString();
            var repository = new DatabaseObjectProvider();
            repository.CreateBlog("Test", "username", "password", hostName, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty);
            Config.CurrentBlog.Email = "[email protected]";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            DateTime dateCreated = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "testtitle", "testbody", null, dateCreated);

            UnitTestHelper.Create(entry); //persist to db.

            var subtextContext = new Mock<ISubtextContext>();
            string rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(repository);
            Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/archive/2008/01/23/testtitle.aspx");
            var handler = new AtomHandler(subtextContext.Object);

            handler.ProcessRequest();
            HttpContext.Current.Response.Flush();

            var doc = new XmlDocument();
            doc.LoadXml(rssOutput);
            var nsmanager = new XmlNamespaceManager(doc.NameTable);
            nsmanager.AddNamespace("atom", "http://www.w3.org/2005/Atom");

            XmlNodeList itemNodes = doc.SelectNodes("/atom:feed/atom:entry", nsmanager);
            Assert.AreEqual(1, itemNodes.Count, "expected one entry node.");

            Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("atom:title", nsmanager).InnerText,
                            "Not what we expected for the title.");
            string urlFormat = "http://{0}/archive/2008/01/23/{1}.aspx";

            string expectedUrl = string.Format(urlFormat, hostName, "testtitle");

            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("atom:id", nsmanager).InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("atom:link/@href", nsmanager).InnerText,
                            "Not what we expected for the link.");
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:47,代码来源:AtomHandlerTests.cs

示例4: CommentRssHandlerProducesValidEmptyFeed

        public void CommentRssHandlerProducesValidEmptyFeed()
        {
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            //BlogInfo blog = new BlogInfo {
            //    Host = hostName,
            //    Email = "[email protected]",
            //    RFC3229DeltaEncodingEnabled = false,
            //};
            int blogId = new DatabaseObjectProvider().CreateBlog("Test", "username", "password", hostName, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, string.Empty);
            BlogRequest.Current.Blog = new DatabaseObjectProvider().GetBlog(hostName, string.Empty);
            Blog blog = Config.CurrentBlog;
            blog.Host = hostName;
            blog.Email = "[email protected]";
            blog.RFC3229DeltaEncodingEnabled = false;

            DateTime dateCreated = DateTime.UtcNow;
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication(blog, "Author", "Best post EVER", "testbody", null, dateCreated);
            var repository = new Mock<ObjectRepository>();
            repository.Setup(r => r.GetEntry(It.IsAny<int>(), true, true)).Returns(entry);

            int id = UnitTestHelper.Create(entry); //persist to db.

            string rssOutput = null;

            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.FakeSyndicationContext(blog, "/" + id + ".aspx", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(repository.Object);
            subtextContext.Object.RequestContext.RouteData.Values.Add("id", id.ToString());
            Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever/entry");

            var handler = new RssCommentHandler(subtextContext.Object);
            handler.ProcessRequest();

            var doc = new XmlDocument();
            doc.LoadXml(rssOutput);

            XmlNodeList titleNodes = doc.SelectNodes("/rss/channel/title");
            Assert.IsNotNull(titleNodes, "The title node should not be null.");
            Assert.AreEqual("Best post EVER", titleNodes[0].InnerText,
                            "Did not get the expected value of the title node.");
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:43,代码来源:CommentRssHandlerTests.cs

示例5: RssImageUrlConcatenatedProperly

        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 = "[email protected]";
            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.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:21,代码来源:RssWriterTests.cs

示例6: RssHandlerHandlesDoesNotSyndicateFuturePosts

        public void RssHandlerHandlesDoesNotSyndicateFuturePosts()
        {
            // Setup
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            Config.CreateBlog("", "username", "password", hostName, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);
            Config.CurrentBlog.TimeZoneId = TimeZonesTest.HawaiiTimeZoneId;

            //Create two entries, but only include one in main syndication.
            UnitTestHelper.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test",
                                                                                   "Body Rocking", null,
                                                                                   NullValue.NullDateTime));
            Entry futureEntry = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2",
                                                                                 "Body Rocking Pt 2", null,
                                                                                 NullValue.NullDateTime);
            futureEntry.DateSyndicated = Config.CurrentBlog.TimeZone.Now.AddMinutes(20);
            UnitTestHelper.Create(futureEntry);

            string rssOutput = null;
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            Mock<UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(1, itemNodes.Count, "expected one item node.");

            Assert.AreEqual("Title Test", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the first title.");
            Assert.AreEqual("Body Rocking",
                            itemNodes[0].SelectSingleNode("description").InnerText.Substring(0, "Body Rocking".Length),
                            "Not what we expected for the first body.");

            Config.CurrentBlog.TimeZoneId = TimeZonesTest.PacificTimeZoneId;

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);
            subtextContext = new Mock<ISubtextContext>();
            rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(2, itemNodes.Count, "Expected two items in the feed now.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:51,代码来源:RssHandlerTests.cs

示例7: RssWriterProducesValidFeedWithEnclosureFromDatabase

        public void RssWriterProducesValidFeedWithEnclosureFromDatabase()
        {
            string hostName = UnitTestHelper.GenerateUniqueString() + ".com";
            Config.CreateBlog("Test", "username", "password", hostName, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);
            Config.CurrentBlog.Email = "[email protected]";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "testtitle", "testbody", null,
                                                                           NullValue.NullDateTime);
            entry.DateCreated = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.DateSyndicated = entry.DateCreated;
            int entryId = UnitTestHelper.Create(entry); //persist to db.

            string enclosureUrl = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            string enclosureMimeType = "audio/mp3";
            long enclosureSize = 26707573;

            Enclosure enc =
                UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true);
            Enclosures.Create(enc);

            var subtextContext = new Mock<ISubtextContext>();
            string rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            Mock<UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/archive/2008/01/23/testtitle.aspx");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(1, itemNodes.Count, "expected one item nodes.");

            string urlFormat = "http://{0}/archive/2008/01/23/{1}.aspx";
            string expectedUrl = string.Format(urlFormat, hostName, "testtitle");

            Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the title.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("link").InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("guid").InnerText,
                            "Not what we expected for the guid.");
            Assert.AreEqual(enclosureUrl, itemNodes[0].SelectSingleNode("enclosure/@url").InnerText,
                            "Not what we expected for the enclosure url.");
            Assert.AreEqual(enclosureMimeType, itemNodes[0].SelectSingleNode("enclosure/@type").InnerText,
                            "Not what we expected for the enclosure mimetype.");
            Assert.AreEqual(enclosureSize.ToString(), itemNodes[0].SelectSingleNode("enclosure/@length").InnerText,
                            "Not what we expected for the enclosure size.");
            Assert.AreEqual(expectedUrl + "#feedback", itemNodes[0].SelectSingleNode("comments").InnerText,
                            "Not what we expected for the link.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:54,代码来源:RssHandlerTests.cs

示例8: RssWriterProducesValidFeedFromDatabase

        public void RssWriterProducesValidFeedFromDatabase()
        {
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            Config.CreateBlog("Test", "username", "password", hostName, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);

            Config.CurrentBlog.Email = "[email protected]";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author",
                                                                           "testtitle",
                                                                           "testbody",
                                                                           null,
                                                                           NullValue.NullDateTime);
            entry.DateCreated = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.DateSyndicated = entry.DateCreated;
            UnitTestHelper.Create(entry); //persist to db.

            string rssOutput = null;
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            Mock<UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/archive/2008/01/23/testtitle.aspx");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(1, itemNodes.Count, "expected one item nodes.");

            string urlFormat = "http://{0}/archive/2008/01/23/{1}.aspx";
            string expectedUrl = string.Format(urlFormat, hostName, "testtitle");

            Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the title.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("link").InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("guid").InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl + "#feedback", itemNodes[0].SelectSingleNode("comments").InnerText,
                            "Not what we expected for the link.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:43,代码来源:RssHandlerTests.cs

示例9: RssHandlerSortsByDateSyndicated

        public void RssHandlerSortsByDateSyndicated()
        {
            // Setup
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            Config.CreateBlog("", "username", "password", hostName, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);

            //Create two entries.
            int firstId =
                UnitTestHelper.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test",
                                                                                       "Body Rocking"));
            Thread.Sleep(1000);
            UnitTestHelper.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2",
                                                                                   "Body Rocking Pt 2"));

            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            string rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            Mock<UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);

            //Expect the first item to be the second entry.
            Assert.AreEqual("Title Test 2", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the first title.");
            Assert.AreEqual("Title Test", itemNodes[1].SelectSingleNode("title").InnerText,
                            "Not what we expected for the second title.");

            //Remove first entry from syndication.
            Entry firstEntry = UnitTestHelper.GetEntry(firstId, PostConfig.None, false);
            firstEntry.IncludeInMainSyndication = false;
            firstEntry.Blog = new Blog() { Title = "MyTestBlog" };
            UnitTestHelper.Update(firstEntry, subtextContext.Object);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);
            subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());

            rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(1, itemNodes.Count, "Here we were expeting only one item");

            Thread.Sleep(10);
            //Now add it back in changing the DateSyndicated
            firstEntry.IncludeInMainSyndication = true;
            firstEntry.DateSyndicated = Config.CurrentBlog.TimeZone.Now;
            UnitTestHelper.Update(firstEntry, subtextContext.Object);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);
            subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());

            rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);

            //Expect the second item to be the second entry.
            Assert.AreEqual(2, itemNodes.Count, "Here we were expeting 2 items");
            Assert.AreEqual("Title Test", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the first title.");
            Assert.AreEqual("Title Test 2", itemNodes[1].SelectSingleNode("title").InnerText,
                            "Not what we expected for the second title.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:79,代码来源:RssHandlerTests.cs

示例10: RssHandlerProducesValidRssFeed

        public void RssHandlerProducesValidRssFeed()
        {
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            Config.CreateBlog("", "username", "password", hostName, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);

            UnitTestHelper.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test",
                                                                                   "Body Rocking"));
            Thread.Sleep(50);
            UnitTestHelper.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2",
                                                                                   "Body Rocking Pt 2"));

            var subtextContext = new Mock<ISubtextContext>();
            string rssOutput = null;
            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            Mock<UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);
            Assert.AreEqual(2, itemNodes.Count, "expected two item nodes.");

            Assert.AreEqual("Title Test 2", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the second title.");
            Assert.AreEqual("Title Test", itemNodes[1].SelectSingleNode("title").InnerText,
                            "Not what we expected for the first title.");

            Assert.AreEqual("Body Rocking Pt 2",
                            itemNodes[0].SelectSingleNode("description").InnerText.Substring(0,
                                                                                             "Body Rocking pt 2".Length),
                            "Not what we expected for the second body.");
            Assert.AreEqual("Body Rocking",
                            itemNodes[1].SelectSingleNode("description").InnerText.Substring(0, "Body Rocking".Length),
                            "Not what we expected for the first body.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:37,代码来源:RssHandlerTests.cs

示例11: CommentRssWriterProducesValidFeed

        public void CommentRssWriterProducesValidFeed()
        {
            var blogInfo = new Blog();
            blogInfo.Host = "localhost";
            blogInfo.Email = "[email protected]";
            blogInfo.RFC3229DeltaEncodingEnabled = true;
            blogInfo.Title = "My Blog Rulz";
            blogInfo.TimeZoneId = TimeZonesTest.PacificTimeZoneId;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication(blogInfo, "haacked", "title of the post",
                                                                           "Body of the post.");
            entry.EntryName = "titleofthepost";
            entry.DateCreatedUtc =
                entry.DatePublishedUtc =
                entry.DateModifiedUtc = DateTime.ParseExact("2006/01/30 02:00", "yyyy/MM/dd hh:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            entry.Id = 1001;

            var comment = new FeedbackItem(FeedbackType.Comment);
            comment.Id = 1002;
            comment.DateCreatedUtc =
                comment.DateModifiedUtc = DateTime.ParseExact("2006/02/01 08:00", "yyyy/MM/dd hh:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
            comment.Title = "re: titleofthepost";
            comment.ParentEntryName = entry.EntryName;
            comment.ParentDateCreatedUtc = entry.DateCreatedUtc;
            comment.Body = "<strong>I rule!</strong>";
            comment.Author = "Jane Schmane";
            comment.Email = "[email protected]";
            comment.EntryId = entry.Id;

            var comments = new List<FeedbackItem>();
            comments.Add(comment);

            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.FakeSyndicationContext(blogInfo, "/Subtext.Web/Whatever", "Subtext.Web", null);
            Mock<HttpContextBase> httpContext = Mock.Get(subtextContext.Object.RequestContext.HttpContext);
            httpContext.Setup(c => c.Request.ApplicationPath).Returns("/Subtext.Web");
            Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.FeedbackUrl(It.IsAny<FeedbackItem>())).Returns(
                "/Subtext.Web/archive/2006/02/01/titleofthepost.aspx#" + comment.Id);
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns(
                "/Subtext.Web/archive/2006/02/01/titleofthepost.aspx");

            var writer = new CommentRssWriter(new StringWriter(), comments, entry, subtextContext.Object);

            Assert.IsTrue(entry.HasEntryName, "This entry should have an entry name.");

            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>title of the post</title>" + Environment.NewLine
                              + indent(2) +
                              @"<link>http://localhost/Subtext.Web/archive/2006/02/01/titleofthepost.aspx</link>" +
                              Environment.NewLine
                              + indent(2) + @"<description>Body of the post.</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>title of the post</title>" + Environment.NewLine
                              + indent(3) + @"<url>http://localhost/Subtext.Web/images/RSS2Image.gif</url>" +
                              Environment.NewLine
                              + indent(3) +
                              @"<link>http://localhost/Subtext.Web/archive/2006/02/01/titleofthepost.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>re: titleofthepost</title>" + Environment.NewLine
                              + indent(3) +
                              @"<link>http://localhost/Subtext.Web/archive/2006/02/01/titleofthepost.aspx#1002</link>" +
                              Environment.NewLine
                              + indent(3) + @"<description>&lt;strong&gt;I rule!&lt;/strong&gt;</description>" +
                              Environment.NewLine
                              + indent(3) + @"<dc:creator>Jane Schmane</dc:creator>" + Environment.NewLine
                              + indent(3) +
                              @"<guid>http://localhost/Subtext.Web/archive/2006/02/01/titleofthepost.aspx#1002</guid>" +
                              Environment.NewLine
                              + indent(3) + @"<pubDate>Wed, 01 Feb 2006 08:00:00 GMT</pubDate>" + Environment.NewLine
                              + indent(2) + @"</item>" + Environment.NewLine
                              + indent() + @"</channel>" + Environment.NewLine
                              + @"</rss>";

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

            // Act
            string rss = writer.Xml;

            // Assert
            UnitTestHelper.AssertStringsEqualCharacterByCharacter(expected, rss);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:96,代码来源:CommentRssWriterTests.cs

示例12: RssWriterHandlesRFC3229DeltaEncoding

        public void RssWriterHandlesRFC3229DeltaEncoding()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            var blogInfo = new Blog();
            BlogRequest.Current.Blog = blogInfo;
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "";
            blogInfo.Email = "[email protected]";
            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.");
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:87,代码来源:RssWriterTests.cs

示例13: RssWriterSendsWholeFeedWhenRFC3229Disabled

        public void RssWriterSendsWholeFeedWhenRFC3229Disabled()
        {
            UnitTestHelper.SetHttpContextWithBlogRequest("localhost", "", "Subtext.Web");

            var blogInfo = new Blog();
            BlogRequest.Current.Blog = blogInfo;
            blogInfo.Host = "localhost";
            blogInfo.Subfolder = "";
            blogInfo.Email = "[email protected]";
            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>" +
//.........这里部分代码省略.........
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:101,代码来源:RssWriterTests.cs

示例14: RssWriterProducesValidFeed

        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 = "[email protected]";
            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 = "[email protected]";
            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
//.........这里部分代码省略.........
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:101,代码来源:RssWriterTests.cs


注:本文中的Mock.FakeSyndicationContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。