public void ParameterProtoTest() { MultiplyInput input = new MultiplyInput(); input.FirstNumber = 6; input.SecondNumber = 7; input.Prefix = "the prefix"; var memInputStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(memInputStream, input); MultiplyOutput output = new MultiplyOutput(); output.ResultNumber = 42; output.ResultString = "the result"; var memOutputStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(memOutputStream, output); resultMessage.CallResult.ProtoParam = memOutputStream.ToArray(); MultiplyOutput x = service.Multiply(input); Assert.That(x.ResultNumber, Is.EqualTo(42)); Assert.That(x.ResultString, Is.EqualTo("the result")); client.Verify(c => c.Call("ISampleService", "Multiply", It.Is <RpcMessage.Parameter[]>( p => p.Length == 1 && p[0].ProtoParam.SequenceEqual(memInputStream.ToArray())), null, null)); }
public MultiplyOutput Multiply(MultiplyInput input) { var output = new MultiplyOutput(); output.ResultNumber = input.FirstNumber*input.SecondNumber; output.ResultString = input.Prefix + output.ResultNumber; return output; }
public static bool IsEquivalentTo(this MultiplyInput message, byte[] otherMessageBytes) { var memStream = new MemoryStream(otherMessageBytes); MultiplyInput otherMessage = Serializer.Deserialize <MultiplyInput>(memStream); return(message.IsEquivalentTo(otherMessage)); }
public void FromMessageProtoTest() { Assert.That(ParameterConverter.FromMessage(message, typeof(MultiplyInput), out param, out errorMsg), Is.False); Assert.That(ParameterConverter.ProtoFromMessage(message, typeof(MultiplyInput), ref param, ref errorMsg), Is.False); var messageParam = new MultiplyInput(); messageParam.FirstNumber = 10; messageParam.SecondNumber = 11; messageParam.Prefix = "Test"; var memStream = new MemoryStream(); Serializer.Serialize(memStream, messageParam); message.ProtoParam = memStream.ToArray(); Assert.That(ParameterConverter.FromMessage(message, typeof(MultiplyInput), out param, out errorMsg), Is.True); MultiplyInput result = (MultiplyInput)param; Assert.That(result.FirstNumber, Is.EqualTo(10)); Assert.That(result.SecondNumber, Is.EqualTo(11)); Assert.That(result.Prefix, Is.EqualTo("Test")); Assert.That(ParameterConverter.ProtoFromMessage(message, typeof(MultiplyInput), ref param, ref errorMsg), Is.True); result = (MultiplyInput)param; Assert.That(result.FirstNumber, Is.EqualTo(10)); Assert.That(result.SecondNumber, Is.EqualTo(11)); Assert.That(result.Prefix, Is.EqualTo("Test")); }
public static bool IsEquivalentTo(this MultiplyInput message, MultiplyInput otherMessage) { if (message.FirstNumber != otherMessage.FirstNumber || message.SecondNumber != otherMessage.SecondNumber || message.Prefix != otherMessage.Prefix) return false; return true; }
public MultiplyOutput Multiply(MultiplyInput input) { var output = new MultiplyOutput(); output.ResultNumber = input.FirstNumber * input.SecondNumber; output.ResultString = input.Prefix + output.ResultNumber; return(output); }
public static bool IsEquivalentTo(this MultiplyInput message, MultiplyInput otherMessage) { if (message.FirstNumber != otherMessage.FirstNumber || message.SecondNumber != otherMessage.SecondNumber || message.Prefix != otherMessage.Prefix) { return(false); } return(true); }
public void ToMessageProtoTest() { var inputMessage = new MultiplyInput(); inputMessage.FirstNumber = 20; inputMessage.SecondNumber = 21; inputMessage.Prefix = "Test"; var memStream = new MemoryStream(); Serializer.Serialize(memStream, inputMessage); Assert.That(ParameterConverter.ToMessage(inputMessage, out message, out errorMsg), Is.True); Assert.That(message.ProtoParam.SequenceEqual(memStream.ToArray()), Is.True); }
public void ParameterProtoTest() { var input = new MultiplyInput(); input.FirstNumber = 6; input.SecondNumber = 7; input.Prefix = "Answer is "; var memStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(memStream, input); testParamCallMessage.CallMessage.Method = "Multiply"; testParamCallMessage.CallMessage.Parameters.Add(new RpcMessage.Parameter { ProtoParam = memStream.ToArray() }); server.ReceiveCall(testParamCallMessage); controller.Verify(c => c.Send(It.Is <RpcMessage>(m => IsTestProtoParamResultMessageCorrect(m)))); }
public void ParameterProtoTest() { var input = new MultiplyInput(); input.FirstNumber = 6; input.SecondNumber = 7; input.Prefix = "Answer is "; var memStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(memStream, input); testParamCallMessage.CallMessage.Method = "Multiply"; testParamCallMessage.CallMessage.Parameters.Add(new RpcMessage.Parameter { ProtoParam = memStream.ToArray() }); server.ReceiveCall(testParamCallMessage); controller.Verify(c => c.Send(It.Is<RpcMessage>(m => IsTestProtoParamResultMessageCorrect(m)))); }
public void ParameterProtoTest() { MultiplyInput input = new MultiplyInput(); input.FirstNumber = 6; input.SecondNumber = 7; input.Prefix = "the prefix"; var memInputStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(memInputStream, input); MultiplyOutput output = new MultiplyOutput(); output.ResultNumber = 42; output.ResultString = "the result"; var memOutputStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(memOutputStream, output); resultMessage.CallResult.ProtoParam = memOutputStream.ToArray(); MultiplyOutput x = service.Multiply(input); Assert.That(x.ResultNumber, Is.EqualTo(42)); Assert.That(x.ResultString, Is.EqualTo("the result")); client.Verify(c => c.Call("ISampleService", "Multiply", It.Is<RpcMessage.Parameter[]>( p => p.Length == 1 && p[0].ProtoParam.SequenceEqual(memInputStream.ToArray())), null, null)); }