2 // XmlMessageFormatterTest.cs -
3 // NUnit Test Cases for XmlMessageFormatterTest
6 // Michael Barker <mike@middlesoft.co.uk>
8 // Copyright (C) 2008 Michael Barker
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Messaging;
34 using NUnit.Framework;
37 namespace MonoTests.System.Messaging
40 public class XmlMessageFormatterTest
44 Mono.Messaging.IMessage msg1;
46 Mono.Messaging.IMessage msg2;
51 mock1 = new DynamicMock (typeof (Mono.Messaging.IMessage));
52 msg1 = (Mono.Messaging.IMessage) mock1.MockInstance;
53 mock2 = new DynamicMock (typeof (Mono.Messaging.IMessage));
54 msg2 = (Mono.Messaging.IMessage) mock2.MockInstance;
58 public void FormatString ()
60 Type[] t = { typeof (string) };
61 string s = "this is a test string";
63 Stream ms = new MemoryStream ();
64 mock1.ExpectAndReturn ("get_BodyStream", ms);
65 mock1.ExpectAndReturn ("get_BodyStream", ms);
67 mock2.Expect ("set_BodyStream", ms);
68 mock2.ExpectAndReturn ("get_BodyStream", ms);
69 mock2.ExpectAndReturn ("get_BodyStream", ms);
71 Message m = TestUtils.CreateMessage (msg1);
73 XmlMessageFormatter xmlF = new XmlMessageFormatter ();
75 m.Formatter.Write (m, s);
76 Stream stream = m.BodyStream;
78 Assert.AreEqual (typeof (string), xmlF.TargetTypes[0]);
80 Assert.IsTrue (stream.Length > 0);
82 Message m2 = TestUtils.CreateMessage (msg2);
83 m2.Formatter = new XmlMessageFormatter (t);
84 m2.BodyStream = stream;
86 Assert.AreEqual (s, (string) m2.Formatter.Read (m2), "The string did not serialise/deserialise properly");
94 public void FormatComplexObject ()
96 Type[] ts = { typeof (Thingy) };
97 Stream ms = new MemoryStream ();
98 mock1.ExpectAndReturn ("get_BodyStream", ms);
99 mock1.ExpectAndReturn ("get_BodyStream", ms);
101 mock2.Expect ("set_BodyStream", ms);
102 mock2.ExpectAndReturn ("get_BodyStream", ms);
103 mock2.ExpectAndReturn ("get_BodyStream", ms);
105 Thingy t0 = new Thingy();
107 t0.Sss = "Some Text";
108 t0.Ttt = DateTime.Now;
110 Message m = TestUtils.CreateMessage (msg1);
111 m.Formatter = new XmlMessageFormatter (ts);
112 m.Formatter.Write (m, t0);
113 Stream stream = m.BodyStream;
115 Assert.IsTrue (stream.Length > 0);
117 Message m2 = TestUtils.CreateMessage (msg2);
118 m2.Formatter = new XmlMessageFormatter (ts);
119 m2.BodyStream = stream;
120 Thingy t1 = (Thingy) m2.Formatter.Read (m2);
122 Assert.AreEqual (t0.Iii, t1.Iii, "The int did not serialise/deserialise properly");
123 Assert.AreEqual (t0.Sss, t1.Sss, "The string did not serialise/deserialise properly");
124 Assert.AreEqual (t0.Ttt, t1.Ttt, "The date did not serialise/deserialise properly");
134 private DateTime ttt;
146 public DateTime Ttt {