XmlMtomDictionaryWriterTest.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // XmlMtomDictionaryWriterTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2009 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.IO;
  31. using System.Text;
  32. using System.Xml;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Xml
  35. {
  36. [TestFixture]
  37. public class XmlMtomDictionaryWriterTest
  38. {
  39. // Nothing gave me either multi-parted MTOM message or
  40. // xop-included xml so far ...
  41. [Test]
  42. public void UseCase1 ()
  43. {
  44. MemoryStream ms = new MemoryStream ();
  45. var w = XmlDictionaryWriter.CreateMtomWriter (ms, Encoding.UTF8, 10000, "sTaRt", "myboundary", "urn:foo", false, false);
  46. w.WriteStartDocument ();
  47. w.WriteStartElement ("root");
  48. w.WriteRaw ("RAW");
  49. w.WriteStartElement ("foo");
  50. w.WriteChars (new char [] {'b', 'c', 'd'}, 0, 3);
  51. w.WriteBase64 (new byte [] {50, 60, 70}, 0, 3);
  52. w.WriteArray ("", "arr", "", new bool [] {true,false,true},0,3);
  53. w.WriteValue (new MyStreamProvider ());
  54. w.WriteString ("999\r\n\r\n666");
  55. w.WriteEndElement ();
  56. //w.WriteProcessingInstruction ("pi", "data");
  57. w.WriteEndElement (); // it outputs end of mime data.
  58. w.WriteStartElement ("root"); // it is in the next part).
  59. w.WriteEndElement (); // it does not close current part.
  60. w.WriteEndDocument (); // no effect.
  61. w.WriteStartElement ("root");
  62. w.WriteEndElement ();
  63. w.WriteStartElement ("root");
  64. w.WriteEndElement ();
  65. w.WriteEndDocument ();
  66. w.Flush ();
  67. ms.Position = 0;
  68. // there are some insiginificant output differences
  69. Assert.AreEqual (usecase1, new StreamReader (ms).ReadToEnd ().Replace ("<root />", "<root/>"));
  70. }
  71. string usecase1 = @"
  72. --myboundary
  73. Content-ID: <urn:foo>
  74. Content-Transfer-Encoding: 8bit
  75. Content-Type: application/xop+xml;charset=utf-8;type=""sTaRt""
  76. <root>RAW<foo>bcdMjxG<arr>true</arr><arr>false</arr><arr>true</arr>AQIDBAU=999&#xD;
  77. &#xD;
  78. 666</foo></root>
  79. --myboundary--
  80. <root/><root/><root/>".Replace ("\n", "\r\n");
  81. }
  82. class MyStreamProvider : IStreamProvider
  83. {
  84. public Stream GetStream ()
  85. {
  86. return new MemoryStream (new byte [] {1, 2, 3, 4, 5});
  87. }
  88. public void ReleaseStream (Stream s)
  89. {
  90. }
  91. }
  92. }
  93. #endif