Esempio n. 1
0
        public void CommentRssHandlerProducesValidEmptyFeed()
        {
            string hostName = System.Guid.NewGuid().ToString().Replace("-", "") + ".com";
            Assert.IsTrue(Config.CreateBlog("Test", "username", "password", hostName, string.Empty));

            StringBuilder sb = new StringBuilder();
            TextWriter output = new StringWriter(sb);

            DateTime dateCreated = DateTime.Now;

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "", "", "", output);
            Config.CurrentBlog.Email = "*****@*****.**";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "Best post EVER", "testbody", null, dateCreated);
            int id = Entries.Create(entry); //persist to db.
            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "", "", string.Format("/2006/04/01/{0}.aspx", id), output);

            RssCommentHandler handler = new RssCommentHandler();
            handler.ProcessRequest(HttpContext.Current);
            HttpContext.Current.Response.Flush();

            string rssOutput = sb.ToString();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(rssOutput);
            Console.Write(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.");
        }
Esempio n. 2
0
        public void CommentRssHandlerProducesValidEmptyFeed()
        {
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            //BlogInfo blog = new BlogInfo {
            //    Host = hostName,
            //    Email = "*****@*****.**",
            //    RFC3229DeltaEncodingEnabled = false,
            //};
            int blogId = Config.CreateBlog("Test", "username", "password", hostName, string.Empty);

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

            blog.Host  = hostName;
            blog.Email = "*****@*****.**";
            blog.RFC3229DeltaEncodingEnabled = false;


            DateTime dateCreated = DateTime.Now;
            Entry    entry       = UnitTestHelper.CreateEntryInstanceForSyndication(blog, "Author", "Best post EVER", "testbody",
                                                                                    null, dateCreated);
            var repository = new Mock <ObjectProvider>();

            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 <UrlHelper> 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.");
        }
Esempio n. 3
0
        public void CommentRssHandlerProducesValidEmptyFeed()
        {
            string hostName = UnitTestHelper.GenerateUniqueHostname();
            //BlogInfo blog = new BlogInfo {
            //    Host = hostName,
            //    Email = "*****@*****.**",
            //    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 = "*****@*****.**";
            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.");
        }