コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: SampleService.cs プロジェクト: Reen/protobuf-remote
 public MultiplyOutput Multiply(MultiplyInput input)
 {
     var output = new MultiplyOutput();
     output.ResultNumber = input.FirstNumber*input.SecondNumber;
     output.ResultString = input.Prefix + output.ResultNumber;
     return output;
 }
コード例 #3
0
        public static bool IsEquivalentTo(this MultiplyInput message, byte[] otherMessageBytes)
        {
            var           memStream    = new MemoryStream(otherMessageBytes);
            MultiplyInput otherMessage = Serializer.Deserialize <MultiplyInput>(memStream);

            return(message.IsEquivalentTo(otherMessage));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
 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;
 }
コード例 #6
0
        public MultiplyOutput Multiply(MultiplyInput input)
        {
            var output = new MultiplyOutput();

            output.ResultNumber = input.FirstNumber * input.SecondNumber;
            output.ResultString = input.Prefix + output.ResultNumber;
            return(output);
        }
コード例 #7
0
 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);
 }
コード例 #8
0
        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);
        }
コード例 #9
0
        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))));
        }
コード例 #10
0
ファイル: RpcServerTest.cs プロジェクト: Reen/protobuf-remote
        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))));
        }
コード例 #11
0
ファイル: ProxyTest.cs プロジェクト: Reen/protobuf-remote
        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));
        }