Esempio n. 1
0
        private static void TestMessageSerialization()
        {
            CallRequest msg1 = new CallRequest();

            msg1.MethodInfoId    = Guid.NewGuid();
            msg1.Target          = Guid.NewGuid();
            msg1.ParameterValues = new object[] { 1, 2, 3 };
            byte[] data = msg1.ToBytes();

            CallRequest msg2 = (CallRequest)MessageManager.Create(msg1.Id, data);

            Debug.Assert(msg2.Id == msg1.Id);
            Debug.Assert(object.Equals(msg1.Target, msg2.Target));
            Debug.Assert(msg1.ParameterValues.Length == msg2.ParameterValues.Length);

            CallRequest msg3;

            using (MemoryStream ms = new MemoryStream())
            {
                msg1.BeginWrite(ms);

                Thread.Sleep(100);
                ms.Position = 0;

                var ar = AMessage.BeginRead(ms);
                Thread.Sleep(100);

                msg3 = ar.GetMessage() as CallRequest;
            }

            Debug.Assert(msg1.Id == msg3.Id);
            Debug.Assert(object.Equals(msg1.Target, msg3.Target));
            Debug.Assert(msg1.ParameterValues.Length == msg3.ParameterValues.Length);

            var mainMethodInfo         = typeof(Program).GetMethod("Main", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
            MethodInfoAnswer miAnswer1 = new MethodInfoAnswer();

            miAnswer1.MethodInfoId = Guid.NewGuid();
            miAnswer1.MethodInfo   = mainMethodInfo;
            byte[]           miAnswerBytes = miAnswer1.ToBytes();
            MethodInfoAnswer miAnswer2     = (MethodInfoAnswer)AMessage.Create(miAnswer1.Id, miAnswerBytes);

            Debug.Assert(miAnswer1.MethodInfo == miAnswer2.MethodInfo);
        }