2 // XmlMtomDictionaryWriterTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2009 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
35 using NUnit.Framework;
37 namespace MonoTests.System.Xml
40 public class XmlMtomDictionaryWriterTest
42 // Nothing gave me either multi-parted MTOM message or
43 // xop-included xml so far ...
46 public void UseCase1 ()
48 MemoryStream ms = new MemoryStream ();
49 var w = XmlDictionaryWriter.CreateMtomWriter (ms, Encoding.UTF8, 10000, "sTaRt", "myboundary", "urn:foo", false, false);
50 w.WriteStartDocument ();
51 w.WriteStartElement ("root");
53 w.WriteStartElement ("foo");
54 w.WriteChars (new char [] {'b', 'c', 'd'}, 0, 3);
55 w.WriteBase64 (new byte [] {50, 60, 70}, 0, 3);
56 w.WriteArray ("", "arr", "", new bool [] {true,false,true},0,3);
57 w.WriteValue (new MyStreamProvider ());
58 w.WriteString ("999\r\n\r\n666");
60 //w.WriteProcessingInstruction ("pi", "data");
61 w.WriteEndElement (); // it outputs end of mime data.
62 w.WriteStartElement ("root"); // it is in the next part).
63 w.WriteEndElement (); // it does not close current part.
64 w.WriteEndDocument (); // no effect.
65 w.WriteStartElement ("root");
67 w.WriteStartElement ("root");
69 w.WriteEndDocument ();
72 // there are some insiginificant output differences
73 Assert.AreEqual (usecase1, new StreamReader (ms).ReadToEnd ().Replace ("<root />", "<root/>"));
79 Content-Transfer-Encoding: 8bit
80 Content-Type: application/xop+xml;charset=utf-8;type=""sTaRt""
82 <root>RAW<foo>bcdMjxG<arr>true</arr><arr>false</arr><arr>true</arr>AQIDBAU=999
86 <root/><root/><root/>".Replace ("\n", "\r\n");
89 class MyStreamProvider : IStreamProvider
91 public Stream GetStream ()
93 return new MemoryStream (new byte [] {1, 2, 3, 4, 5});
96 public void ReleaseStream (Stream s)