2
0

Atom10SerializerTest.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // Microsoft.TeamFoundation.VersionControl.Client.Atom10SerializerTest
  3. //
  4. // Authors:
  5. // Joel Reed ([email protected])
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. using System;
  28. using System.IO;
  29. using System.Net;
  30. using System.Xml;
  31. using System.ServiceModel.Syndication;
  32. namespace System.ServiceModel.Syndication
  33. {
  34. using NUnit.Framework;
  35. [TestFixture]
  36. public class Atom10SerializerTest : Atom10Serializer
  37. {
  38. string FileToString(string path)
  39. {
  40. string x;
  41. using (StreamReader sr = new StreamReader(path))
  42. {
  43. x = sr.ReadToEnd();
  44. }
  45. return x;
  46. }
  47. string FeedToString(string id)
  48. {
  49. return FileToString(String.Format("Test/{0}.atom.xml", id));
  50. }
  51. string SyndicationFeedToString(SyndicationFeed f)
  52. {
  53. // try to keep the time here stable so it doesn't trip up the string compare
  54. f.LastUpdatedTime = FeedLib.FixedChangedDate;
  55. StringWriter strWriter = new StringWriter();
  56. using (XmlTextWriter writer = new XmlTextWriter(strWriter))
  57. {
  58. writer.Formatting = Formatting.Indented;
  59. Atom10Serializer serializer = new Atom10Serializer();
  60. serializer.WriteTo(writer, f);
  61. }
  62. return strWriter.ToString();
  63. }
  64. [Test]
  65. public void Serializer_Properties()
  66. {
  67. Assert.AreEqual("feed", FeedName);
  68. Assert.AreEqual("http://www.w3.org/2005/Atom", FeedNamespace);
  69. Assert.AreEqual("entry", ItemName);
  70. Assert.AreEqual("http://www.w3.org/2005/Atom", ItemNamespace);
  71. }
  72. [Test]
  73. public void Serialize_EmptyFeed()
  74. {
  75. string expected = FeedToString("EmptyFeed");
  76. string actual = SyndicationFeedToString(FeedLib.EmptyFeed);
  77. Assert.AreEqual(expected, actual);
  78. }
  79. [Test]
  80. public void Serialize_FeedNoItems()
  81. {
  82. string expected = FeedToString("FeedNoItems");
  83. string actual = SyndicationFeedToString(FeedLib.FeedNoItems);
  84. Assert.AreEqual(expected, actual);
  85. }
  86. [Test]
  87. public void Serialize_FeedWithItems()
  88. {
  89. string expected = FeedToString("FeedWithItems");
  90. string actual = SyndicationFeedToString(FeedLib.FeedWithItems);
  91. Assert.AreEqual(expected, actual);
  92. }
  93. [Test]
  94. public void Serialize_FeedNoItemsSimpleProps()
  95. {
  96. string expected = FeedToString("FeedNoItemsSimpleProps");
  97. string actual = SyndicationFeedToString(FeedLib.FeedNoItemsSimpleProps);
  98. Assert.AreEqual(expected, actual);
  99. }
  100. }
  101. }