private static XmlNodeList GetRssHandlerItemNodes(StringBuilder sb) { RssHandler handler = new RssHandler(); handler.ProcessRequest(HttpContext.Current); HttpContext.Current.Response.Flush(); string rssOutput = sb.ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(rssOutput); return doc.SelectNodes("/rss/channel/item"); }
private static XmlNodeList GetRssHandlerItemNodes(ISubtextContext context, ref string rssOutput) { var handler = new RssHandler(context); handler.ProcessRequest(); var doc = new XmlDocument(); doc.LoadXml(rssOutput); return doc.SelectNodes("/rss/channel/item"); }
public void TestCompressedFeedWorks() { string hostName = Guid.NewGuid().ToString().Replace("-", "") + ".com"; StringBuilder sb = new StringBuilder(); TextWriter output = new StringWriter(sb); SimulatedHttpRequest workerRequest = UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "", "", "", output); workerRequest.Headers.Add("Accept-Encoding", "gzip"); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostName, string.Empty)); Config.CurrentBlog.UseSyndicationCompression = true; Entries.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test", "Body Rocking")); Thread.Sleep(50); Entries.Create(UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2", "Body Rocking Pt 2")); RssHandler handler = new RssHandler(); Assert.IsNotNull(HttpContext.Current.Request.Headers, "Headers collection is null! Not Good."); handler.ProcessRequest(HttpContext.Current); //I'm cheating here! MethodInfo method = typeof(HttpResponse).GetMethod("FilterOutput", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(HttpContext.Current.Response, new object[] {}); HttpContext.Current.Response.Flush(); MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(sb.ToString())); Stream deflated = UnitTestHelper.GetDeflatedResponse("gzip", stream); string rssOutput; using(StreamReader reader = new StreamReader(deflated)) { rssOutput = reader.ReadToEnd(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(rssOutput); XmlNodeList itemNodes = doc.SelectNodes("/rss/channel/item"); 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."); }