public void FromMessage() { var serializers = new Mock <IStoreObjectSerializers>(); { serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>())) .Returns(true); serializers.Setup(s => s.SerializerFor(It.IsAny <Type>())) .Returns(new NonTransformingObjectSerializer()); } var translator = new CommandInvocationResponseConverter(serializers.Object); var msg = new CommandInvokedResponseMessage( new EndpointId("a"), new MessageId(), new object()); var data = translator.FromMessage(msg); Assert.IsInstanceOf(typeof(CommandInvocationResponseData), data); Assert.AreSame(msg.Id, data.Id); Assert.AreSame(msg.Sender, data.Sender); Assert.AreSame(msg.InResponseTo, data.InResponseTo); Assert.AreEqual( msg.Result.GetType().FullName, ((CommandInvocationResponseData)data).ReturnedType.FullName); Assert.AreSame(msg.Result, ((CommandInvocationResponseData)data).Result); }
public void Invoke(ICommunicationMessage message) { var msg = message as CommandInvokedMessage; if (msg == null) { Debug.Assert(false, "The message is of the incorrect type."); return; } var invocation = msg.Invocation; m_Diagnostics.Log( LevelToLog.Trace, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Received request to execute command: {0}", invocation.Command)); try { var id = invocation.Command; CommandDefinition commandSet; try { commandSet = m_Commands.CommandToInvoke(id); } catch (UnknownCommandException) { m_Diagnostics.Log( LevelToLog.Trace, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Command invokation was requested for {0} from {1} but this command was not registered.", id, msg.Sender)); var failureResult = new FailureMessage(m_Current, msg.Id); m_SendMessage(msg.Sender, failureResult, CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending); return; } var result = commandSet.Invoke(message.Sender, message.Id, invocation.Parameters); ICommunicationMessage responseMessage; if (commandSet.HasReturnValue) { responseMessage = new CommandInvokedResponseMessage(m_Current, msg.Id, result); } else { responseMessage = new SuccessMessage(m_Current, msg.Id); } m_SendMessage(msg.Sender, responseMessage, CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending); } catch (Exception e) { HandleCommandExecutionFailure(msg, e); } }