SyndicationItemTest.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // SyndicationItemTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if !MOBILE
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Collections.ObjectModel;
  32. using System.IO;
  33. using System.Runtime.Serialization;
  34. using System.Text;
  35. using System.Xml;
  36. using System.ServiceModel.Syndication;
  37. using NUnit.Framework;
  38. using QName = System.Xml.XmlQualifiedName;
  39. namespace MonoTests.System.ServiceModel.Syndication
  40. {
  41. [TestFixture]
  42. public class SyndicationItemTest
  43. {
  44. [Test]
  45. [ExpectedException (typeof (ArgumentNullException))]
  46. public void AddPermalinkNull ()
  47. {
  48. SyndicationItem item = new SyndicationItem ();
  49. item.AddPermalink (null);
  50. }
  51. [Test]
  52. public void SetNullForProperties ()
  53. {
  54. SyndicationItem item = new SyndicationItem ();
  55. item.BaseUri = null;
  56. item.Copyright = null;
  57. item.Content = null;
  58. item.Id = null;
  59. item.SourceFeed = null;
  60. item.Summary = null;
  61. item.Title = null;
  62. }
  63. [Test]
  64. public void LastUpdatedTimeBeforePublishDate ()
  65. {
  66. SyndicationItem item = new SyndicationItem ();
  67. item.PublishDate = new DateTimeOffset (new DateTime (2007, 12, 10));
  68. item.LastUpdatedTime = new DateTimeOffset (new DateTime (2007, 12, 9));
  69. }
  70. [Test]
  71. public void AddPermalink ()
  72. {
  73. SyndicationItem item = new SyndicationItem ();
  74. Assert.AreEqual (0, item.Links.Count, "#1");
  75. item.AddPermalink (new Uri ("http://mono-project.com/index.rss.20071210"));
  76. Assert.AreEqual (1, item.Links.Count, "#2");
  77. SyndicationLink link = item.Links [0];
  78. Assert.AreEqual ("http://mono-project.com/index.rss.20071210", link.Uri.ToString (), "#3");
  79. Assert.AreEqual ("alternate", link.RelationshipType, "#4");
  80. }
  81. [Test]
  82. public void Clone ()
  83. {
  84. SyndicationItem item = new SyndicationItem ();
  85. item.AddPermalink (new Uri ("http://mono-project.com/index.rss.20071210"));
  86. item.Id = Guid.NewGuid ().ToString ();
  87. item.BaseUri = new Uri ("http://mono-project.com");
  88. item.Authors.Add (new SyndicationPerson ("[email protected]"));
  89. item.SourceFeed = new SyndicationFeed ();
  90. item.SourceFeed.Items = new SyndicationItem [] {new SyndicationItem ()};
  91. SyndicationItem clone = item.Clone ();
  92. Assert.AreEqual (1, clone.Links.Count, "#1");
  93. Assert.AreEqual (item.Id, clone.Id, "#2"); // hmm ...
  94. Assert.AreEqual ("http://mono-project.com/", clone.BaseUri.ToString (), "#3");
  95. // LAMESPEC: .NET fails to clone it
  96. // Assert.IsFalse (Object.ReferenceEquals (item.BaseUri, clone.BaseUri), "#4"); // should not be just a shallow copy
  97. Assert.IsNull (clone.Title, "#5");
  98. Assert.IsNotNull (clone.SourceFeed, "#6");
  99. Assert.IsFalse (Object.ReferenceEquals (item.SourceFeed, clone.SourceFeed), "#7"); // ... not just a shallow copy??
  100. // items in the SourceFeed are not cloned, but Items property is not null
  101. Assert.IsNotNull (clone.SourceFeed.Items, "#8-1");
  102. Assert.IsFalse (clone.SourceFeed.Items.GetEnumerator ().MoveNext (), "#8-2");
  103. Assert.AreEqual (1, clone.Authors.Count, "#9");
  104. SyndicationPerson person = clone.Authors [0];
  105. Assert.IsFalse (Object.ReferenceEquals (item.Authors [0], person), "#10"); // should not be just a shallow copy
  106. Assert.AreEqual ("[email protected]", person.Email, "#11");
  107. }
  108. [Test]
  109. public void GetRss20Formatter ()
  110. {
  111. SyndicationItem item = new SyndicationItem ();
  112. Rss20ItemFormatter f = item.GetRss20Formatter ();
  113. Assert.AreEqual (true, f.SerializeExtensionsAsAtom, "#1");
  114. }
  115. [Test]
  116. [ExpectedException (typeof (XmlException))]
  117. public void LoadNonAtomRss ()
  118. {
  119. SyndicationItem.Load (XmlReader.Create (new StringReader ("<dummy />")));
  120. }
  121. [Test]
  122. [ExpectedException (typeof (XmlException))]
  123. public void LoadFeed ()
  124. {
  125. // feed is not allowed.
  126. SyndicationItem.Load (XmlReader.Create (new StringReader ("<feed xmlns=\"http://www.w3.org/2005/Atom\"></feed>")));
  127. }
  128. [Test]
  129. public void LoadEntry ()
  130. {
  131. SyndicationItem.Load (XmlReader.Create (new StringReader ("<entry xmlns=\"http://www.w3.org/2005/Atom\"></entry>")));
  132. }
  133. }
  134. }
  135. #endif