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;
36 using NUnit.Framework;
39 namespace MonoTests.Mono.Messaging.RabbitMQ
42 public class XmlMessageFormatterTest
53 mock1 = new DynamicMock (typeof (IMessage));
54 msg1 = (IMessage) mock1.MockInstance;
55 mock2 = new DynamicMock (typeof (IMessage));
56 msg2 = (IMessage) mock2.MockInstance;
60 public void FormatString ()
62 Type[] t = { typeof (string) };
63 string s = "this is a test string";
65 Stream ms = new MemoryStream ();
66 mock1.ExpectAndReturn ("get_BodyStream", ms);
67 mock1.ExpectAndReturn ("get_BodyStream", ms);
69 mock2.ExpectAndReturn ("get_BodyStream", ms);
70 mock2.ExpectAndReturn ("get_BodyStream", ms);
72 Message m = TestUtils.CreateMessage (msg1);
74 XmlMessageFormatter xmlF = new XmlMessageFormatter ();
76 m.Formatter.Write (m, s);
77 Stream stream = m.BodyStream;
79 Assert.AreEqual (typeof (string), xmlF.TargetTypes[0]);
81 Assert.IsTrue (stream.Length > 0);
83 Message m2 = TestUtils.CreateMessage (msg2);
84 m2.Formatter = new XmlMessageFormatter (t);
86 Assert.AreEqual (s, (string) m2.Formatter.Read (m2), "The string did not serialise/deserialise properly");
94 public void FormatComplexObject ()
96 Type[] ts = { typeof (Thingy2) };
97 Stream ms = new MemoryStream ();
98 mock1.ExpectAndReturn ("get_BodyStream", ms);
99 mock1.ExpectAndReturn ("get_BodyStream", ms);
101 mock2.ExpectAndReturn ("get_BodyStream", ms);
102 mock2.ExpectAndReturn ("get_BodyStream", ms);
104 Thingy2 t0 = new Thingy2();
106 t0.Sss = "Some Text";
107 t0.Ttt = DateTime.Now;
109 Message m = TestUtils.CreateMessage (msg1);
110 m.Formatter = new XmlMessageFormatter (ts);
111 m.Formatter.Write (m, t0);
112 Stream stream = m.BodyStream;
114 Assert.IsTrue (stream.Length > 0);
116 Message m2 = TestUtils.CreateMessage (msg2);
117 m2.Formatter = new XmlMessageFormatter (ts);
118 Thingy2 t1 = (Thingy2) m2.Formatter.Read (m2);
120 Assert.AreEqual (t0.Iii, t1.Iii, "The int did not serialise/deserialise properly");
121 Assert.AreEqual (t0.Sss, t1.Sss, "The string did not serialise/deserialise properly");
122 Assert.AreEqual (t0.Ttt, t1.Ttt, "The date did not serialise/deserialise properly");
135 private DateTime ttt;
147 public DateTime Ttt {