public void GetRss20Formatter() { SyndicationItem item = new SyndicationItem(); Rss20ItemFormatter f = item.GetRss20Formatter(); Assert.AreEqual(true, f.SerializeExtensionsAsAtom, "#1"); }
public void ReadFrom_Comments() { Rss20ItemFormatter f = new Rss20ItemFormatter(); f.ReadFrom(CreateReader("<item><comments>comment</comments></item>")); Assert.IsNotNull(f.Item, "#1"); // 'comments' is treated as extensions ... Assert.AreEqual(1, f.Item.ElementExtensions.Count, "#2"); }
public void ReadFrom2() { SyndicationItem item = new SyndicationItem(); Rss20ItemFormatter f = new Rss20ItemFormatter(item); Assert.IsTrue(object.ReferenceEquals(item, f.Item), "Item #1"); f.ReadFrom(CreateReader("<item><title>test</title></item>")); Assert.IsFalse(object.ReferenceEquals(item, f.Item), "Item #2"); }
public static void Snippets16() { // <Snippet16> Rss20ItemFormatter myItemRssFormatter = new Rss20ItemFormatter(typeof(MySyndicationItem)); XmlReader rssReader = XmlReader.Create("http://Contoso/Feeds/MyFeed/Items"); myItemRssFormatter.ReadFrom(rssReader); rssReader.Close(); // </Snippet16> }
public void ReadXml_TitleOnly() { Rss20ItemFormatter f = new Rss20ItemFormatter(); ((IXmlSerializable)f).ReadXml(CreateReader("<item><title>test</title></item>")); Assert.IsNotNull(f.Item.Title, "#1"); Assert.AreEqual("test", f.Item.Title.Text, "#2"); ((IXmlSerializable)f).ReadXml(CreateReader("<dummy><title>test</title></dummy>")); // it is ok }
public static void Snippet44() { // <Snippet44> SyndicationItem item = new SyndicationItem("Item Title", "Item Content", new Uri("http://Item/Alternate/Link"), "itemID", DateTimeOffset.Now); Rss20ItemFormatter rssFormatter = item.GetRss20Formatter(true); XmlWriter writer = XmlWriter.Create("output.xml"); rssFormatter.WriteTo(writer); writer.Close(); // </Snippet44> }
public static void Snippet19() { // <Snippet19> SyndicationItem item = new SyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://Contoso/ItemOne"), "TestItemID", DateTime.Now); XmlWriter rssWriter = XmlWriter.Create("RSS.xml"); Rss20ItemFormatter rssFormatter = new Rss20ItemFormatter(item); rssFormatter.WriteTo(rssWriter); rssWriter.Close(); // </Snippet19> }
public void ReadFrom1() { Rss20ItemFormatter f = new Rss20ItemFormatter(); Assert.IsNull(f.Item, "#1"); f.ReadFrom(CreateReader("<item><title>test</title></item>")); SyndicationItem item1 = f.Item; Assert.IsNotNull(f.Item.Title, "#2"); Assert.AreEqual("test", f.Item.Title.Text, "#3"); f.ReadFrom(CreateReader("<item><title>test</title></item>")); Assert.IsFalse(object.ReferenceEquals(item1, f.Item), "#4"); }
// </Snippet10> // <Snippet11> public void SerializeItem(SyndicationItem item) { Atom10ItemFormatter atomFormatter = item.GetAtom10Formatter(); Rss20ItemFormatter rssFormatter = item.GetRss20Formatter(); XmlWriter atomWriter = XmlWriter.Create("atom.xml"); XmlWriter rssWriter = XmlWriter.Create("rss.xml"); atomFormatter.WriteTo(atomWriter); rssFormatter.WriteTo(rssWriter); atomWriter.Close(); rssWriter.Close(); }
public static void Snippet18() { // <Snippet18> Rss20ItemFormatter feedFormatter = new Rss20ItemFormatter(); XmlReader rssReader = XmlReader.Create("http://Contoso/Feeds/MyFeed"); if (feedFormatter.CanRead(rssReader)) { feedFormatter.ReadFrom(rssReader); rssReader.Close(); } // </Snippet18> }
public static void Snippet12() { // <Snippet12> MySyndicationItem item = new MySyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://Contoso/ItemOne"), "TestItemID", DateTime.Now); item.Links.Add(new SyndicationLink(new Uri("http://Contoso"), "alternate", "MyItemLink", "text/html", 100)); item.PublishDate = new DateTime(1968, 2, 23); item.LastUpdatedTime = DateTime.Today; item.SourceFeed = new SyndicationFeed(); item.Summary = new TextSyndicationContent("This the item summary"); XmlWriter rssWriter = XmlWriter.Create("RssItem.xml"); Rss20ItemFormatter <MySyndicationItem> formatter = new Rss20ItemFormatter <MySyndicationItem>(item, true); // </Snippet12> }
public void ReadFromGuidPermaLink() { const string xml1 = "<item><guid isPermaLink=\"false\">urn:myid</guid><description /></item>"; using (XmlReader r = CreateReader(xml1)) { var rss = new Rss20ItemFormatter(); rss.ReadFrom(r); Assert.AreEqual("urn:myid", rss.Item.Id); } const string xml2 = "<item><guid isPermaLink=\"true\">urn:myid</guid><description /></item>"; using (XmlReader r = CreateReader(xml2)) { var rss = new Rss20ItemFormatter(); rss.ReadFrom(r); Assert.AreEqual("urn:myid", rss.Item.Id); } }
public void ReadFrom_Enclosure() { Rss20ItemFormatter f = new Rss20ItemFormatter(); // .NET bug: it allows extension attributes, but rejects extension elements. // f.ReadFrom (CreateReader ("<item><enclosure url='urn:foo' length='50' type='text/html' wcf='wtf'><extended /></enclosure></item>")); f.ReadFrom(CreateReader("<item><enclosure url='urn:foo' length='50' type='text/html' wcf='wtf'></enclosure></item>")); // 'enclosure' is treated as SyndicationLink Assert.AreEqual(1, f.Item.Links.Count, "#1"); SyndicationLink link = f.Item.Links [0]; Assert.AreEqual(50, link.Length, "#2"); Assert.AreEqual("urn:foo", link.Uri.ToString(), "#3"); Assert.AreEqual("text/html", link.MediaType, "#4"); Assert.AreEqual("enclosure", link.RelationshipType, "#5"); Assert.AreEqual(1, link.AttributeExtensions.Count, "#6"); //Assert.AreEqual (1, link.ElementExtensions.Count, "#7"); }
public void CanRead() { Rss20ItemFormatter f = new Rss20ItemFormatter(); Assert.IsFalse(f.CanRead(CreateReader("<rss>")), "#1"); Assert.IsTrue(f.CanRead(CreateReader("<item>")), "#2"); Assert.IsFalse(f.CanRead(CreateReader("<item xmlns='urn:foo'>")), "#3"); Assert.IsFalse(f.CanRead(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'>")), "#4"); Assert.IsFalse(f.CanRead(CreateReader("<hoge>")), "#5"); XmlReader r = CreateReader("<item></item>"); r.Read(); // element r.Read(); // endelement Assert.IsFalse(f.CanRead(r), "#6"); r = CreateReader("<item><title>test</title></item>"); r.Read(); // item r.Read(); // title Assert.IsFalse(f.CanRead(r), "#7"); }
public void SerializeExtensionsAsAtom() { Rss20ItemFormatter f = new Rss20ItemFormatter(); Assert.IsTrue(f.SerializeExtensionsAsAtom, "#1"); }
public void Version() { Rss20ItemFormatter f = new Rss20ItemFormatter(); Assert.AreEqual("Rss20", f.Version, "#1"); }
public void ReadFrom_WrongDate2() { Rss20ItemFormatter f = new Rss20ItemFormatter(); f.ReadFrom(CreateReader("<item><pubDate>2000-01-01T00:00:00</pubDate></item>")); }
public void ReadFrom_WrongDate1() { Rss20ItemFormatter f = new Rss20ItemFormatter(); f.ReadFrom(CreateReader("<item><pubDate /></item>")); }