++2009-01-05 Michael Barker <mike@middlesoft.co.uk>
++
++ * Makefile: Added nunit.mocks to test build
++ * Mono.Messaging.RabbitMQ_test.dll.sources: Added additional formatter
++ tests.
++
2008-09-29 Michael Barker <mike@middlesoft.co.uk>
* AssemblyInfo.cs: New
/r:Mono.Messaging.dll \
/r:RabbitMQ.Client
--TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:0618 -nowarn:219 -nowarn:169
++TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:0618 -nowarn:219 -nowarn:169 \
++ /r:nunit.mocks.dll
include ../../build/library.make
Mono.Messaging.RabbitMQ/TransactionMessagingTest.cs
Mono.Messaging.RabbitMQ/SelectorTest.cs
Mono.Messaging.RabbitMQ/AsyncReceiveTest.cs
--Mono.Messaging.RabbitMQ/AsyncPeekTest.cs
++Mono.Messaging.RabbitMQ/AsyncPeekTest.cs
++Mono.Messaging.RabbitMQ/BinaryMessageFormatterTest.cs
++Mono.Messaging.RabbitMQ/XmlMessageFormatterTest.cs
++Mono.Messaging.RabbitMQ/TestUtils.cs
++Mono.Messaging.RabbitMQ/MessageTest.cs
--- /dev/null
--- /dev/null
++//
++// BinaryMessageFormatterTest.cs -
++// NUnit Test Cases for BinaryMessageFormatter
++//
++// Author:
++// Michael Barker <mike@middlesoft.co.uk>
++//
++// Copyright (C) 2008 Michael Barker
++//
++// Permission is hereby granted, free of charge, to any person obtaining
++// a copy of this software and associated documentation files (the
++// "Software"), to deal in the Software without restriction, including
++// without limitation the rights to use, copy, modify, merge, publish,
++// distribute, sublicense, and/or sell copies of the Software, and to
++// permit persons to whom the Software is furnished to do so, subject to
++// the following conditions:
++//
++// The above copyright notice and this permission notice shall be
++// included in all copies or substantial portions of the Software.
++//
++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++//
++
++using System;
++using System.IO;
++using System.Messaging;
++
++using Mono.Messaging;
++
++using NUnit.Framework;
++using NUnit.Mocks;
++
++namespace MonoTests.Mono.Messaging.RabbitMQ
++{
++ [TestFixture]
++ public class BinaryMessageFormatterTest
++ {
++
++ DynamicMock mock1;
++ IMessage msg1;
++ DynamicMock mock2;
++ IMessage msg2;
++
++ [SetUp]
++ public void SetUp ()
++ {
++ mock1 = new DynamicMock (typeof (IMessage));
++ msg1 = (IMessage) mock1.MockInstance;
++ mock2 = new DynamicMock (typeof (IMessage));
++ msg2 = (IMessage) mock2.MockInstance;
++ }
++
++ [Test]
++ public void FormatString ()
++ {
++ string s = "this is a test string";
++ Stream ms = new MemoryStream ();
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++ mock1.Expect ("set_BodyType", 768);
++
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++
++ Message m = TestUtils.CreateMessage (msg1);
++ m.Formatter = new BinaryMessageFormatter ();
++ m.Formatter.Write (m, s);
++
++ Stream stream = m.BodyStream;
++ Assert.IsTrue (stream.Length > 0);
++
++ Message m2 = TestUtils.CreateMessage (msg2);
++ m2.Formatter = new BinaryMessageFormatter ();
++
++ Assert.AreEqual(s, m2.Formatter.Read (m2), "The string did not serialise/deserialise properly");
++ mock1.Verify ();
++ mock2.Verify ();
++ }
++
++ [Test]
++ public void FormatComplexObject ()
++ {
++ Stream ms = new MemoryStream ();
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++
++ Thingy2 t0 = new Thingy2();
++ t0.Iii = 42;
++ t0.Sss = "Some Text";
++ t0.Ttt = DateTime.Now;
++
++ Message m = TestUtils.CreateMessage (msg1);
++ m.Formatter = new BinaryMessageFormatter ();
++ m.Formatter.Write (m, t0);
++ Stream stream = m.BodyStream;
++
++ Assert.IsTrue (stream.Length > 0);
++
++ Message m2 = TestUtils.CreateMessage (msg2);
++ m2.Formatter = new BinaryMessageFormatter ();
++ Thingy2 t1 = (Thingy2) m2.Formatter.Read (m2);
++
++ Assert.AreEqual(t0.Iii, t1.Iii, "The string did not serialise/deserialise properly");
++ Assert.AreEqual(t0.Sss, t1.Sss, "The string did not serialise/deserialise properly");
++ Assert.AreEqual(t0.Ttt, t1.Ttt, "The string did not serialise/deserialise properly");
++ mock1.Verify ();
++ mock2.Verify ();
++ }
++ }
++}
++
++2009-01-05 Michael Barker <mike@middlesoft.co.uk>
++
++ * BinaryMessageFormatter.cs, XMLMessageFormatterTest.cs, TestUtils.cs,
++ MessageTest.cs: Moved in from System.Messaging namespace.
++
2009-01-03 Michael Barker <mike@middlesoft.co.uk>
* AsyncPeekTest.cs: Added test for handling exceptions aysnchronously.
--- /dev/null
--- /dev/null
++//
++// MessageTest.cs -
++// NUnit Test Cases for MessageQueuePermissionAttribute
++//
++// Author:
++// Michael Barker <sebastien@ximian.com>
++//
++// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
++//
++// Permission is hereby granted, free of charge, to any person obtaining
++// a copy of this software and associated documentation files (the
++// "Software"), to deal in the Software without restriction, including
++// without limitation the rights to use, copy, modify, merge, publish,
++// distribute, sublicense, and/or sell copies of the Software, and to
++// permit persons to whom the Software is furnished to do so, subject to
++// the following conditions:
++//
++// The above copyright notice and this permission notice shall be
++// included in all copies or substantial portions of the Software.
++//
++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++//
++
++using NUnit.Framework;
++using NUnit.Mocks;
++using System;
++//using System.Messaging;
++using System.Security;
++using System.Security.Permissions;
++using System.Reflection;
++
++using Mono.Messaging;
++
++namespace MonoTests.Mono.Messaging.RabbitMQ {
++
++ [TestFixture]
++ public class MessageTest {
++
++ DynamicMock messageMock;
++ IMessage iMessage;
++
++ [SetUp]
++ public void SetUp ()
++ {
++ messageMock = new DynamicMock (typeof (IMessage));
++ iMessage = (IMessage) messageMock.MockInstance;
++ }
++
++ [Test]
++ public void SetProperties ()
++ {
++ messageMock.Expect ("set_AcknowledgeType",
++ AcknowledgeTypes.FullReachQueue);
++
++ System.Messaging.Message m = TestUtils.CreateMessage (iMessage);
++ m.AcknowledgeType = System.Messaging.AcknowledgeTypes.FullReachQueue;
++
++ messageMock.Verify ();
++ }
++ }
++}
--- /dev/null
--- /dev/null
++//
++// MessageTest.cs -
++// NUnit Test Cases for MessageQueuePermissionAttribute
++//
++// Author:
++// Michael Barker <sebastien@ximian.com>
++//
++// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
++//
++// Permission is hereby granted, free of charge, to any person obtaining
++// a copy of this software and associated documentation files (the
++// "Software"), to deal in the Software without restriction, including
++// without limitation the rights to use, copy, modify, merge, publish,
++// distribute, sublicense, and/or sell copies of the Software, and to
++// permit persons to whom the Software is furnished to do so, subject to
++// the following conditions:
++//
++// The above copyright notice and this permission notice shall be
++// included in all copies or substantial portions of the Software.
++//
++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++//
++
++using System;
++using System.Messaging;
++using System.Reflection;
++
++using Mono.Messaging;
++
++namespace MonoTests.Mono.Messaging.RabbitMQ {
++
++ public class TestUtils {
++
++ public static Message CreateMessage (IMessage iMessage)
++ {
++ if (iMessage == null)
++ throw new Exception ("Message is null");
++
++ Type[] types = {
++ typeof (IMessage), typeof (object), typeof (IMessageFormatter)
++ };
++
++ ConstructorInfo ci = typeof (Message).GetConstructor (
++ BindingFlags.NonPublic | BindingFlags.Instance,
++ Type.DefaultBinder, types, new ParameterModifier[0]);
++
++ if (ci == null)
++ throw new Exception ("ConstructorInfo is null");
++
++ return (Message) ci.Invoke (new object[] { iMessage, null, null });
++ }
++
++ }
++}
--- /dev/null
--- /dev/null
++//
++// XmlMessageFormatterTest.cs -
++// NUnit Test Cases for XmlMessageFormatterTest
++//
++// Author:
++// Michael Barker <mike@middlesoft.co.uk>
++//
++// Copyright (C) 2008 Michael Barker
++//
++// Permission is hereby granted, free of charge, to any person obtaining
++// a copy of this software and associated documentation files (the
++// "Software"), to deal in the Software without restriction, including
++// without limitation the rights to use, copy, modify, merge, publish,
++// distribute, sublicense, and/or sell copies of the Software, and to
++// permit persons to whom the Software is furnished to do so, subject to
++// the following conditions:
++//
++// The above copyright notice and this permission notice shall be
++// included in all copies or substantial portions of the Software.
++//
++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++//
++
++using System;
++using System.IO;
++using System.Messaging;
++
++using Mono.Messaging;
++
++using NUnit.Framework;
++using NUnit.Mocks;
++
++namespace MonoTests.Mono.Messaging.RabbitMQ
++{
++ [TestFixture]
++ public class XmlMessageFormatterTest
++ {
++
++ DynamicMock mock1;
++ IMessage msg1;
++ DynamicMock mock2;
++ IMessage msg2;
++
++ [SetUp]
++ public void SetUp ()
++ {
++ mock1 = new DynamicMock (typeof (IMessage));
++ msg1 = (IMessage) mock1.MockInstance;
++ mock2 = new DynamicMock (typeof (IMessage));
++ msg2 = (IMessage) mock2.MockInstance;
++ }
++
++ [Test]
++ public void FormatString ()
++ {
++ Type[] t = { typeof (string) };
++ string s = "this is a test string";
++
++ Stream ms = new MemoryStream ();
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++
++ Message m = TestUtils.CreateMessage (msg1);
++
++ XmlMessageFormatter xmlF = new XmlMessageFormatter ();
++ m.Formatter = xmlF;
++ m.Formatter.Write (m, s);
++ Stream stream = m.BodyStream;
++
++ Assert.AreEqual (typeof (string), xmlF.TargetTypes[0]);
++
++ Assert.IsTrue (stream.Length > 0);
++
++ Message m2 = TestUtils.CreateMessage (msg2);
++ m2.Formatter = new XmlMessageFormatter (t);
++
++ Assert.AreEqual (s, (string) m2.Formatter.Read (m2), "The string did not serialise/deserialise properly");
++
++ mock1.Verify ();
++ mock2.Verify ();
++ }
++
++
++ [Test]
++ public void FormatComplexObject ()
++ {
++ Type[] ts = { typeof (Thingy2) };
++ Stream ms = new MemoryStream ();
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++ mock1.ExpectAndReturn ("get_BodyStream", ms);
++
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++ mock2.ExpectAndReturn ("get_BodyStream", ms);
++
++ Thingy2 t0 = new Thingy2();
++ t0.Iii = 42;
++ t0.Sss = "Some Text";
++ t0.Ttt = DateTime.Now;
++
++ Message m = TestUtils.CreateMessage (msg1);
++ m.Formatter = new XmlMessageFormatter (ts);
++ m.Formatter.Write (m, t0);
++ Stream stream = m.BodyStream;
++
++ Assert.IsTrue (stream.Length > 0);
++
++ Message m2 = TestUtils.CreateMessage (msg2);
++ m2.Formatter = new XmlMessageFormatter (ts);
++ Thingy2 t1 = (Thingy2) m2.Formatter.Read (m2);
++
++ Assert.AreEqual (t0.Iii, t1.Iii, "The int did not serialise/deserialise properly");
++ Assert.AreEqual (t0.Sss, t1.Sss, "The string did not serialise/deserialise properly");
++ Assert.AreEqual (t0.Ttt, t1.Ttt, "The date did not serialise/deserialise properly");
++
++ mock1.Verify ();
++ mock2.Verify ();
++ }
++
++ }
++
++ [Serializable]
++ public class Thingy2
++ {
++ private int iii;
++ private string sss;
++ private DateTime ttt;
++
++ public int Iii {
++ get { return iii; }
++ set { iii = value; }
++ }
++
++ public string Sss {
++ get { return sss; }
++ set { sss = value; }
++ }
++
++ public DateTime Ttt {
++ get { return ttt; }
++ set { ttt = value; }
++ }
++ }
++}
++
private readonly string queue;
public static readonly string LOCALHOST = ".";
public static readonly QueueReference DEFAULT = new QueueReference (LOCALHOST, null, false);
++ private static readonly string PRIVATE_STR = "private$";
public QueueReference (string host, string queue, bool isPrivate)
{
public string Queue {
get {
if (isPrivate)
-- return @"private$\" + queue;
++ return PRIVATE_STR + @"\" + queue;
else
return queue;
}
public static bool IsPrivateStr (string s)
{
-- return "private$" == s.ToLower ();
++ return PRIVATE_STR == s.ToLower ();
}
public static string RemoveLeadingSlashes (string s)
public override string ToString ()
{
if (IsPrivate) {
-- return Host + "\\$private\\" + Queue;
++ return Host + "\\" + PRIVATE_STR + "\\" + queue;
} else {
return Host + "\\" + Queue;
}
Mono.Messaging/MessageBaseTest.cs
--Mono.Messaging/QueueReferenceTest.cs
++Mono.Messaging/QueueReferenceTest.cs
"AdministrationQueue default should be null");
Assert.AreEqual (0, m.AppSpecific, "AppSpecific default should be 0");
Assert.AreEqual (true, m.AttachSenderId, "AttachSenderId default should be true");
-- Assert.AreEqual ("", m.AuthenticationProviderName,
-- "AuthenticationProviderName should default to \"\"");
++ Assert.AreEqual ("Microsoft Base Cryptographic Provider, Ver. 1.0", m.AuthenticationProviderName,
++ "AuthenticationProviderName should default to \"Microsoft Base Cryptographic Provider, Ver. 1.0\"");
Assert.AreEqual (System.Messaging.CryptographicProviderType.RsaFull,
m.AuthenticationProviderType,
"AuthenticationProviderType should default to RsaFull");
"Extension should default to an empty array");
Assert.AreEqual (System.Messaging.HashAlgorithm.Sha, m.HashAlgorithm,
"HashAlgorithm should default to Sha");
-- Assert.AreEqual (Guid.Empty.ToString (), m.Id, "Id should default to Guid.Empty");
++ Assert.AreEqual (Guid.Empty.ToString () + "\\0", m.Id, "Id should default to Guid.Empty");
Assert.AreEqual ("", m.Label, "Label should default to \"\"");
Assert.AreEqual (false, m.IsFirstInTransaction, "IsFirstInTransaction should default to false");
Assert.AreEqual (false, m.IsLastInTransaction, "IsLastInTransaction should default to false");
Assert.AreEqual (3, s.Length, "Fail");
Assert.AreEqual (".", s[0], "Fail");
-- QueueReference qr0 = QueueReference.Parse (@"\\host\$private\myqueue");
++ QueueReference qr0 = QueueReference.Parse (@"\\host\private$\myqueue");
Assert.AreEqual ("host", qr0.Host);
Assert.AreEqual (true, qr0.IsPrivate);
-- Assert.AreEqual ("myqueue", qr0.Queue);
++ Assert.AreEqual (@"private$\myqueue", qr0.Queue);
QueueReference qr1 = QueueReference.Parse (@"\\host\myqueue");
Assert.AreEqual ("host", qr1.Host);
Assert.AreEqual ("myqueue", qr1.Queue);
QueueReference qr2 = QueueReference.Parse ("myqueue");
-- Assert.AreEqual (QueueReference.LOCALHOST, qr2.Host);
++ Assert.AreEqual ("localhost", qr2.Host);
Assert.AreEqual (false, qr2.IsPrivate);
Assert.AreEqual ("myqueue", qr2.Queue);
}