WriteRsd() публичный Метод

Writes the RSD for the specified blog into the XmlWriter.
public WriteRsd ( XmlWriter writer, BlogInfo blog ) : void
writer System.Xml.XmlWriter
blog BlogInfo
Результат void
Пример #1
0
        public void WriteRsdWritesTheCorrectRSD()
        {
            //arrange
            var blog = new Blog();
            blog.Id = 8675309;
            blog.Subfolder = "sub";
            blog.Host = "example.com";

            var urlHelper = new Mock<UrlHelper>();
            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.MetaWeblogApiUrl(blog)).Returns(
                new Uri("http://example.com/sub/services/metablogapi.aspx"));

            var builder = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(builder);
            var handler = new RsdHandler(null);

            //act
            handler.WriteRsd(writer, blog, urlHelper.Object);

            //assert
            var xml = new XmlDocument();
            Console.WriteLine(builder);
            xml.LoadXml(builder.ToString());

            var nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("rsd", "http://archipelago.phrasewise.com/rsd");

            XmlNode rootRsdNode = xml.SelectSingleNode("/rsd:rsd", nsmgr);
            Assert.IsNotNull(rootRsdNode, "Could not find the root RSD node.");
            Assert.AreEqual("1.0", rootRsdNode.Attributes["version"].InnerText,
                            "Expected the version attribute to be '1.0'");

            XmlNode engineNameNode = xml.SelectSingleNode("/rsd:rsd/rsd:service/rsd:engineName", nsmgr);
            Assert.IsNotNull(engineNameNode, "Could not find the engineName node.");
            Assert.AreEqual(engineNameNode.InnerText, "Subtext");
            XmlNode node = xml.SelectSingleNode("/rsd:rsd/rsd:service/rsd:apis/rsd:api[@name='MetaWeblog']", nsmgr);
            Assert.IsNotNull(node, "Could not find the metaweblog node.");
            Assert.AreEqual("http://example.com/sub/services/metablogapi.aspx", node.Attributes["apiLink"].Value,
                            "Api link is wrong");

            Assert.AreEqual("8675309", node.Attributes["blogID"].Value, "Blog Id is not set.");
        }
Пример #2
0
        public void WriteRsdWritesTheCorrectRSD(string host, string application, string subfolder, string expected)
        {
            StringBuilder builder = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(builder);
            RsdHandler handler = new RsdHandler();

            BlogInfo blog = new BlogInfo();
            blog.Id = 8675309;
            blog.Subfolder = subfolder;
            blog.Host = host;
            UnitTestHelper.SetHttpContextWithBlogRequest(host, subfolder, application);

            HttpContext.Current.Cache["BlogInfo-" + host + "/" + subfolder] = blog;

            handler.WriteRsd(writer, blog);

            //Now lets assert some things.
            XmlDocument xml = new XmlDocument();
            Console.WriteLine(builder);
            xml.LoadXml(builder.ToString());

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("rsd", "http://archipelago.phrasewise.com/rsd");

            XmlNode rootRsdNode = xml.SelectSingleNode("/rsd:rsd", nsmgr);
            Assert.IsNotNull(rootRsdNode, "Could not find the root RSD node.");
            Assert.AreEqual("1.0", rootRsdNode.Attributes["version"].InnerText, "Expected the version attribute to be '1.0'");

            XmlNode engineNameNode = xml.SelectSingleNode("/rsd:rsd/rsd:service/rsd:engineName", nsmgr);
            Assert.IsNotNull(engineNameNode, "Could not find the engineName node.");
            Assert.AreEqual(engineNameNode.InnerText, "Subtext");
            XmlNode node = xml.SelectSingleNode("/rsd:rsd/rsd:service/rsd:apis/rsd:api[@name='MetaWeblog']", nsmgr);
            Assert.IsNotNull(node, "Could not find the metaweblog node.");
            Assert.AreEqual(expected, node.Attributes["apiLink"].Value, "Api link is wrong");

            Assert.AreEqual("8675309", node.Attributes["blogID"].Value, "Blog Id is not set.");
        }