SyndicationItemTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. using System;
  29. using System.Collections.Generic;
  30. using System.Collections.ObjectModel;
  31. using System.IO;
  32. using System.Runtime.Serialization;
  33. using System.Text;
  34. using System.Xml;
  35. using System.ServiceModel.Syndication;
  36. using NUnit.Framework;
  37. using QName = System.Xml.XmlQualifiedName;
  38. namespace MonoTests.System.ServiceModel.Syndication
  39. {
  40. [TestFixture]
  41. public class SyndicationItemTest
  42. {
  43. [Test]
  44. [ExpectedException (typeof (ArgumentNullException))]
  45. public void AddPermalinkNull ()
  46. {
  47. SyndicationItem item = new SyndicationItem ();
  48. item.AddPermalink (null);
  49. }
  50. [Test]
  51. public void SetNullForProperties ()
  52. {
  53. SyndicationItem item = new SyndicationItem ();
  54. item.BaseUri = null;
  55. item.Copyright = null;
  56. item.Content = null;
  57. item.Id = null;
  58. item.SourceFeed = null;
  59. item.Summary = null;
  60. item.Title = null;
  61. }
  62. [Test]
  63. public void LastUpdatedTimeBeforePublishDate ()
  64. {
  65. SyndicationItem item = new SyndicationItem ();
  66. item.PublishDate = new DateTimeOffset (new DateTime (2007, 12, 10));
  67. item.LastUpdatedTime = new DateTimeOffset (new DateTime (2007, 12, 9));
  68. }
  69. [Test]
  70. public void AddPermalink ()
  71. {
  72. SyndicationItem item = new SyndicationItem ();
  73. Assert.AreEqual (0, item.Links.Count, "#1");
  74. item.AddPermalink (new Uri ("http://mono-project.com/index.rss.20071210"));
  75. Assert.AreEqual (1, item.Links.Count, "#2");
  76. SyndicationLink link = item.Links [0];
  77. Assert.AreEqual ("http://mono-project.com/index.rss.20071210", link.Uri.ToString (), "#3");
  78. Assert.AreEqual ("alternate", link.RelationshipType, "#4");
  79. }
  80. [Test]
  81. public void Clone ()
  82. {
  83. SyndicationItem item = new SyndicationItem ();
  84. item.AddPermalink (new Uri ("http://mono-project.com/index.rss.20071210"));
  85. item.Id = Guid.NewGuid ().ToString ();
  86. item.BaseUri = new Uri ("http://mono-project.com");
  87. item.Authors.Add (new SyndicationPerson ("[email protected]"));
  88. item.SourceFeed = new SyndicationFeed ();
  89. item.SourceFeed.Items = new SyndicationItem [] {new SyndicationItem ()};
  90. SyndicationItem clone = item.Clone ();
  91. Assert.AreEqual (1, clone.Links.Count, "#1");
  92. Assert.AreEqual (item.Id, clone.Id, "#2"); // hmm ...
  93. Assert.AreEqual ("http://mono-project.com/", clone.BaseUri.ToString (), "#3");
  94. // LAMESPEC: .NET fails to clone it
  95. // Assert.IsFalse (Object.ReferenceEquals (item.BaseUri, clone.BaseUri), "#4"); // should not be just a shallow copy
  96. Assert.IsNull (clone.Title, "#5");
  97. Assert.IsNotNull (clone.SourceFeed, "#6");
  98. Assert.IsFalse (Object.ReferenceEquals (item.SourceFeed, clone.SourceFeed), "#7"); // ... not just a shallow copy??
  99. // items in the SourceFeed are not cloned, but Items property is not null
  100. Assert.IsNotNull (clone.SourceFeed.Items, "#8-1");
  101. Assert.IsFalse (clone.SourceFeed.Items.GetEnumerator ().MoveNext (), "#8-2");
  102. Assert.AreEqual (1, clone.Authors.Count, "#9");
  103. SyndicationPerson person = clone.Authors [0];
  104. Assert.IsFalse (Object.ReferenceEquals (item.Authors [0], person), "#10"); // should not be just a shallow copy
  105. Assert.AreEqual ("[email protected]", person.Email, "#11");
  106. }
  107. [Test]
  108. public void GetRss20Formatter ()
  109. {
  110. SyndicationItem item = new SyndicationItem ();
  111. Rss20ItemFormatter f = item.GetRss20Formatter ();
  112. Assert.AreEqual (true, f.SerializeExtensionsAsAtom, "#1");
  113. }
  114. [Test]
  115. [ExpectedException (typeof (XmlException))]
  116. public void LoadNonAtomRss ()
  117. {
  118. SyndicationItem.Load (XmlReader.Create (new StringReader ("<dummy />")));
  119. }
  120. }
  121. }