diff --git a/src/unicast/NServiceBus.Unicast.Tests/Contexts/InterfaceMessage.cs b/src/unicast/NServiceBus.Unicast.Tests/Contexts/InterfaceMessage.cs new file mode 100644 index 00000000000..3b59a1732cf --- /dev/null +++ b/src/unicast/NServiceBus.Unicast.Tests/Contexts/InterfaceMessage.cs @@ -0,0 +1,8 @@ +namespace SomeUserNamespace +{ + using NServiceBus; + + public interface InterfaceMessage:IMessage + { + } +} \ No newline at end of file diff --git a/src/unicast/NServiceBus.Unicast.Tests/Contexts/using_the_unicastbus.cs b/src/unicast/NServiceBus.Unicast.Tests/Contexts/using_the_unicastbus.cs index 098b62771b9..ad25f270956 100644 --- a/src/unicast/NServiceBus.Unicast.Tests/Contexts/using_the_unicastbus.cs +++ b/src/unicast/NServiceBus.Unicast.Tests/Contexts/using_the_unicastbus.cs @@ -3,6 +3,7 @@ namespace NServiceBus.Unicast.Tests using System.Collections.Generic; using System.Linq; using MasterNode; + using MessageInterfaces.MessageMapper.Reflection; using MessageMutator; using NUnit.Framework; using ObjectBuilder; @@ -22,6 +23,7 @@ public class using_a_configured_unicastbus protected Address gatewayAddress; MessageHeaderManager headerManager = new MessageHeaderManager(); + MessageMapper messageMapper = new MessageMapper(); [SetUp] public void SetUp() @@ -59,7 +61,8 @@ public void SetUp() MessageSender = messageSender, Transport = MockRepository.GenerateStub(), SubscriptionStorage = subscriptionStorage, - AutoSubscribe = true + AutoSubscribe = true, + MessageMapper = messageMapper }; bus = unicastBus; ExtensionMethods.SetHeaderAction = headerManager.SetHeader; @@ -71,14 +74,18 @@ protected void RegisterMessageHandlerType() unicastBus.MessageHandlerTypes = new[] { typeof(T) }; } - protected void RegisterMessageType() + protected Address RegisterMessageType() { - unicastBus.RegisterMessageType(typeof(T), new Address(typeof(T).Name, "localhost"), false); + var address = new Address(typeof (T).Name, "localhost"); + RegisterMessageType(address); + return address; } protected void RegisterMessageType(Address address) { + if(typeof(T).IsInterface) + messageMapper.Initialize(new[]{typeof(T)}); unicastBus.RegisterMessageType(typeof(T), address, false); } diff --git a/src/unicast/NServiceBus.Unicast.Tests/NServiceBus.Unicast.Tests.csproj b/src/unicast/NServiceBus.Unicast.Tests/NServiceBus.Unicast.Tests.csproj index 80f68937636..a2c65422980 100644 --- a/src/unicast/NServiceBus.Unicast.Tests/NServiceBus.Unicast.Tests.csproj +++ b/src/unicast/NServiceBus.Unicast.Tests/NServiceBus.Unicast.Tests.csproj @@ -44,6 +44,13 @@ False ..\..\..\build\nservicebus.core\NServiceBus.MasterNode.dll + + False + ..\..\..\build\nservicebus.core\NServiceBus.MessageInterfaces.dll + + + ..\..\..\build\nservicebus.core\NServiceBus.MessageInterfaces.MessageMapper.Reflection.dll + False ..\..\..\build\nservicebus.core\NServiceBus.MessageMutator.dll @@ -75,6 +82,7 @@ + diff --git a/src/unicast/NServiceBus.Unicast.Tests/Sending.cs b/src/unicast/NServiceBus.Unicast.Tests/Sending.cs index e6f53a77d5b..4c3efe2dc02 100644 --- a/src/unicast/NServiceBus.Unicast.Tests/Sending.cs +++ b/src/unicast/NServiceBus.Unicast.Tests/Sending.cs @@ -46,4 +46,33 @@ public void The_gateway_address_should_be_generated_based_on_the_master_node() messageSender.AssertWasCalled(x => x.Send(Arg.Is.Anything, Arg
.Is.Equal(gatewayAddress))); } } + + [TestFixture] + public class When_sending_a_command_message : using_the_unicastbus + { + [Test] + public void Should_specify_the_message_to_be_recoverable() + { + RegisterMessageType(); + + bus.Send(new CommandMessage()); + + messageSender.AssertWasCalled(x => x.Send(Arg.Matches(m => m.Recoverable == true), Arg
.Is.Anything)); + } + } + + + [TestFixture] + public class When_sending_a_interface_message : using_the_unicastbus + { + [Test] + public void Should_specify_the_message_to_be_recoverable() + { + var defaultAddress = RegisterMessageType(); + + bus.Send(m=>{}); + + messageSender.AssertWasCalled(x => x.Send(Arg.Matches(m => m.Recoverable), Arg
.Is.Equal(defaultAddress))); + } + } } \ No newline at end of file diff --git a/src/unicast/NServiceBus.Unicast/UnicastBus.cs b/src/unicast/NServiceBus.Unicast/UnicastBus.cs index d447cd291b8..2752d3fe42f 100644 --- a/src/unicast/NServiceBus.Unicast/UnicastBus.cs +++ b/src/unicast/NServiceBus.Unicast/UnicastBus.cs @@ -1444,10 +1444,12 @@ protected TransportMessage MapTransportMessageFor(object[] rawMessages, Transpor foreach (var message in messages) { - if (recoverableMessageTypes.Contains(message.GetType())) + var messageType = message.GetType(); + + if (recoverableMessageTypes.Any(rt => rt.IsAssignableFrom(messageType))) result.Recoverable = true; - var span = GetTimeToBeReceivedForMessageType(message.GetType()); + var span = GetTimeToBeReceivedForMessageType(messageType); timeToBeReceived = (span < timeToBeReceived ? span : timeToBeReceived); } @@ -1708,4 +1710,4 @@ private class MessageTypeDestinationEventArgs : EventArgs private readonly static ILog Log = LogManager.GetLogger(typeof(UnicastBus)); #endregion } -} +}