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 = "*****@*****.**"; 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."); }
public void AtomWriterProducesValidFeedFromDatabase() { string hostName = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("Test", "username", "password", hostName, string.Empty)); StringBuilder sb = new StringBuilder(); TextWriter output = new StringWriter(sb); UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "", "", "", output); Config.CurrentBlog.Email = "*****@*****.**"; Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false; DateTime dateCreated = DateTime.Now; Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "testtitle", "testbody", null, dateCreated); int id = Entries.Create(entry); //persist to db. AtomHandler handler = new AtomHandler(); handler.ProcessRequest(HttpContext.Current); HttpContext.Current.Response.Flush(); string rssOutput = sb.ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(rssOutput); XmlNamespaceManager nsmanager = new XmlNamespaceManager(doc.NameTable); nsmanager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); Console.Write(rssOutput); Console.WriteLine(doc.ChildNodes[0].Name); 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/{1:yyyy/MM/dd}/{2}.aspx"; string expectedUrl = string.Format(urlFormat, hostName, dateCreated, "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."); }