コード例 #1
0
        public void Test_Check_SizeReduction_When_MessageContainingDefaultValues()
        {
            var serializer = new ProtobufSerializer(null);

            var msg1 = new IDefault_PayloadTable.Call_Invoke { a = 1, b = 2, c = "Test" };
            var msg2 = new IDefault_PayloadTable.CallWithDefault_Invoke { a = 1, b = 2, c = "Test" };

            var bytes1 = serializer.ToBinary(new RequestMessage { InvokePayload = msg1 });
            var bytes2 = serializer.ToBinary(new RequestMessage { InvokePayload = msg2 });

            Assert.InRange(bytes2.Length, 0, bytes1.Length - 1);
        }
コード例 #2
0
        public void Test_Check_SizeReduction_When_MessageContainingDefaultValues()
        {
            var serializer = new ProtobufSerializer(null);

            var msg1 = new IDefault_PayloadTable.Call_Invoke {
                a = 1, b = 2, c = "Test"
            };
            var msg2 = new IDefault_PayloadTable.CallWithDefault_Invoke {
                a = 1, b = 2, c = "Test"
            };

            var bytes1 = serializer.ToBinary(new RequestMessage {
                InvokePayload = msg1
            });
            var bytes2 = serializer.ToBinary(new RequestMessage {
                InvokePayload = msg2
            });

            Assert.InRange(bytes2.Length, 0, bytes1.Length - 1);
        }
コード例 #3
0
        public void TestBuiltinException()
        {
            var serializer = new ProtobufSerializer(null);

            var exception = new ArgumentException("Test");
            var obj = new ResponseMessage { Exception = exception };
            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.Exception.GetType(), obj2.Exception.GetType());
        }
コード例 #4
0
        public void TestSeriDeseri_ReplyMessageWithNothing()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId = 12345678,
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.RequestId, obj2.RequestId);
        }
コード例 #5
0
        public void TestBuiltinException()
        {
            var serializer = new ProtobufSerializer(null);

            var exception = new ArgumentException("Test");
            var obj       = new ResponseMessage {
                Exception = exception
            };
            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.Exception.GetType(), obj2.Exception.GetType());
        }
コード例 #6
0
        public void TestSourceSurrogate()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                ReturnPayload = new Source { Data = "Hello" }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.ReturnPayload.Value, obj2.ReturnPayload.Value);
        }
コード例 #7
0
        public void TestSeriDeseri_ReplyMessageWithNothing()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId = 12345678,
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.RequestId, obj2.RequestId);
        }
コード例 #8
0
        public void TestSurrogateForAddress()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId = 12345678,
                ReturnPayload = new AddressReturnMessage { v = Address.Parse("akka://system@host:1234") }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.ReturnPayload.Value.ToString(), obj2.ReturnPayload.Value.ToString());
        }
コード例 #9
0
        public void TestTypeAliasException()
        {
            var serializer = new ProtobufSerializer(null);

            var exception = new TestException { ErrorCode = 1000, ErrorDetail = "Test" };
            var obj = new ResponseMessage { Exception = exception };
            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.Exception.GetType(), obj2.Exception.GetType());

            var exception2 = (TestException)obj2.Exception;
            Assert.Equal(exception.ErrorCode, exception2.ErrorCode);
            Assert.Equal(exception.ErrorDetail, exception2.ErrorDetail);
        }
コード例 #10
0
        public void Test_Serialize_MessageContainingDefaultValues()
        {
            var serializer = new ProtobufSerializer(null);

            var msg = new IDefault_PayloadTable.CallWithDefault_Invoke { a = 2, b = 2, c = "Test" };
            var obj = new RequestMessage { InvokePayload = msg };

            var bytes = serializer.ToBinary(obj);
            var obj2 = (RequestMessage)serializer.FromBinary(bytes, null);
            var msg2 = (IDefault_PayloadTable.CallWithDefault_Invoke)obj2.InvokePayload;

            Assert.Equal(msg.a, msg2.a);
            Assert.Equal(msg.b, msg2.b);
            Assert.Equal(msg.c, msg2.c);
        }
コード例 #11
0
        public void TestSeriDeseri_RequestMessage()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new RequestMessage
            {
                RequestId = 12345678,
                InvokePayload = new TestInvokableMessage { a = "Hello", b = "World" }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (RequestMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.RequestId, obj2.RequestId);
            Assert.Equal(((TestInvokableMessage)obj.InvokePayload).a, ((TestInvokableMessage)obj2.InvokePayload).a);
            Assert.Equal(((TestInvokableMessage)obj.InvokePayload).b, ((TestInvokableMessage)obj2.InvokePayload).b);
        }
コード例 #12
0
        public void TestSeriDeseri_ReplyMessageWithException()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId = 12345678,
                Exception = new Exception("Test-Exception")
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.RequestId, obj2.RequestId);
            Assert.NotNull(obj2.Exception);
        }
コード例 #13
0
        public void TestSurrogateDirectives()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                ReturnPayload = new Source2 {
                    Data = "Hello"
                }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.ReturnPayload.Value, obj2.ReturnPayload.Value);
        }
コード例 #14
0
        public void TestSurrogateForAddress()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId     = 12345678,
                ReturnPayload = new AddressReturnMessage {
                    v = Address.Parse("akka://system@host:1234")
                }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.ReturnPayload.Value.ToString(), obj2.ReturnPayload.Value.ToString());
        }
コード例 #15
0
        public void TestSeriDeseri_ReplyWithResult()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId     = 12345678,
                ReturnPayload = new TestReturnMessage {
                    v = "HelloWorld"
                }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, typeof(TestReturnMessage));

            Assert.Equal(obj.RequestId, obj2.RequestId);
            Assert.Equal(((TestReturnMessage)obj.ReturnPayload).Value, ((TestReturnMessage)obj2.ReturnPayload).Value);
        }
コード例 #16
0
        public void Test_Serialize_MessageContainingDefaultValues()
        {
            var serializer = new ProtobufSerializer(null);

            var msg = new IDefault_PayloadTable.CallWithDefault_Invoke {
                a = 2, b = 2, c = "Test"
            };
            var obj = new RequestMessage {
                InvokePayload = msg
            };

            var bytes = serializer.ToBinary(obj);
            var obj2  = (RequestMessage)serializer.FromBinary(bytes, null);
            var msg2  = (IDefault_PayloadTable.CallWithDefault_Invoke)obj2.InvokePayload;

            Assert.Equal(msg.a, msg2.a);
            Assert.Equal(msg.b, msg2.b);
            Assert.Equal(msg.c, msg2.c);
        }
コード例 #17
0
        public void TestSurrogateForIActorRef()
        {
            var system     = ActorSystem.Create("Sys");
            var serializer = new ProtobufSerializer((ExtendedActorSystem)system);
            var actor      = system.ActorOf <DummyActor>("TestActor");

            var obj = new ResponseMessage
            {
                ReturnPayload = new ActorReturnMessage {
                    v = actor
                }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.ReturnPayload.Value, obj2.ReturnPayload.Value);
        }
コード例 #18
0
        public void TestSeriDeseri_RequestMessage()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new RequestMessage
            {
                RequestId     = 12345678,
                InvokePayload = new TestInvokableMessage {
                    a = "Hello", b = "World"
                }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (RequestMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.RequestId, obj2.RequestId);
            Assert.Equal(((TestInvokableMessage)obj.InvokePayload).a, ((TestInvokableMessage)obj2.InvokePayload).a);
            Assert.Equal(((TestInvokableMessage)obj.InvokePayload).b, ((TestInvokableMessage)obj2.InvokePayload).b);
        }
コード例 #19
0
        public void TestSeriDeseri_NotificationMessage()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new NotificationMessage
            {
                ObserverId     = 10,
                NotificationId = 5,
                InvokePayload  = new TestNotificationMessage {
                    a = "Namaste"
                }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (NotificationMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.ObserverId, obj2.ObserverId);
            Assert.Equal(obj.NotificationId, obj2.NotificationId);
            Assert.Equal(((TestNotificationMessage)obj.InvokePayload).a, ((TestNotificationMessage)obj2.InvokePayload).a);
        }
コード例 #20
0
        public void TestTypeAliasException()
        {
            var serializer = new ProtobufSerializer(null);

            var exception = new TestException {
                ErrorCode = 1000, ErrorDetail = "Test"
            };
            var obj = new ResponseMessage {
                Exception = exception
            };
            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);

            Assert.Equal(obj.Exception.GetType(), obj2.Exception.GetType());

            var exception2 = (TestException)obj2.Exception;

            Assert.Equal(exception.ErrorCode, exception2.ErrorCode);
            Assert.Equal(exception.ErrorDetail, exception2.ErrorDetail);
        }
コード例 #21
0
        public void TestSeriDeseri_NotificationMessage()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new NotificationMessage
            {
                ObserverId = 10,
                NotificationId = 5,
                InvokePayload = new TestNotificationMessage { a = "Namaste" }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (NotificationMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.ObserverId, obj2.ObserverId);
            Assert.Equal(obj.NotificationId, obj2.NotificationId);
            Assert.Equal(((TestNotificationMessage)obj.InvokePayload).a, ((TestNotificationMessage)obj2.InvokePayload).a);
        }
コード例 #22
0
        public void TestSurrogateForIActorRef()
        {
            var system = ActorSystem.Create("Sys");
            var serializer = new ProtobufSerializer((ExtendedActorSystem)system);
            var actor = system.ActorOf<DummyActor>("TestActor");

            var obj = new ResponseMessage
            {
                ReturnPayload = new ActorReturnMessage { v = actor }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.ReturnPayload.Value, obj2.ReturnPayload.Value);
        }
コード例 #23
0
        public void TestSeriDeseri_ReplyWithResult()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId = 12345678,
                ReturnPayload = new TestReturnMessage { v = "HelloWorld" }
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, typeof(TestReturnMessage));
            Assert.Equal(obj.RequestId, obj2.RequestId);
            Assert.Equal(((TestReturnMessage)obj.ReturnPayload).Value, ((TestReturnMessage)obj2.ReturnPayload).Value);
        }
コード例 #24
0
        public void TestSeriDeseri_ReplyMessageWithException()
        {
            var serializer = new ProtobufSerializer(null);

            var obj = new ResponseMessage
            {
                RequestId = 12345678,
                Exception = new Exception("Test-Exception")
            };

            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.RequestId, obj2.RequestId);
            Assert.NotNull(obj2.Exception);
        }