public void ProtobufSerialization()
        {
            var fmt1 = new OELibProtobufFormatter.OELibProtobufFormatter();

            var go     = new AutoResetEvent(false);
            var server =
                new CommunicationServer <ServerSideConnection>(new IPEndPoint(IPAddress.Any, 1027))
            {
                Formatter = fmt1
            };

            server.Start();
            server.ClientConnected += (s, e) => go.Set();
            var client = new ClientSideConnection(fmt1);

            client.Start("127.0.0.1", 1027);
            var ok = go.WaitOne(500);

            Assert.IsTrue(ok);
            var go2 = new AutoResetEvent(false);

            client.MessageReceived += (s, e) =>
            {
                if (e is Echo3)
                {
                    go2.Set();
                }
            };

            server.Connections.First().SendMessage(new Echo3());
            var ok2 = go2.WaitOne(500);

            Assert.IsTrue(ok2);
        }
        public void CallMethodResponseSerialization()
        {
            var fmt1 = new OELibProtobufFormatter.OELibProtobufFormatter();
            var assemblyQualifiedName = typeof(Echo).AssemblyQualifiedName;

            // ReSharper disable once AssignNullToNotNullAttribute
            fmt1.SerializationHelper.ManualSerilaizationActions.Add(assemblyQualifiedName,
                                                                    new Tuple <Action <System.IO.Stream, object>, Func <System.IO.Stream, string, object> >(
                                                                        (s, o) => {  }, (s, g) => new Echo()));
            var go     = new AutoResetEvent(false);
            var server =
                new CommunicationServer <ServerSideConnection>(new IPEndPoint(IPAddress.Any, 1030))
            {
                Formatter = fmt1
            };

            server.Start();
            server.ClientConnected += (s, e) => go.Set();
            var client = new ClientSideConnection(fmt1);

            client.Start("127.0.0.1", 1030);
            var ok = go.WaitOne(500);

            Assert.IsTrue(ok);
            var go2 = new AutoResetEvent(false);
            CallMethodResponse ee = null;

            client.MessageReceived += (s, e) =>
            {
                ee = e as CallMethodResponse;
                if (ee != null)
                {
                    go2.Set();
                }
            };
            server.Connections.First().SendMessage(
                new CallMethodResponse(new CallMethod("MethodName", new object[] {}, null), new Echo3(), new NullReferenceException())
                );
            var ok2 = go2.WaitOne(500);

            Assert.IsTrue(ok2);
            Assert.IsTrue(ee.Response is Echo3);
            Assert.IsTrue(ee.Exception is NullReferenceException);
        }
        public void ManualSerialization()
        {
            var fmt1 = new OELibProtobufFormatter.OELibProtobufFormatter();
            var AssemblyQualifiedName = typeof(Echo).AssemblyQualifiedName;

            fmt1.SerializationHelper.ManualSerilaizationActions.Add(AssemblyQualifiedName,
                                                                    new Tuple <Action <System.IO.Stream, object>, Func <System.IO.Stream, string, object> >(
                                                                        (s, o) => {  }, (s, g) => new Echo()));

            var go     = new AutoResetEvent(false);
            var server =
                new CommunicationServer <ServerSideConnection>(new IPEndPoint(IPAddress.Any, 1025))
            {
                Formatter = fmt1
            };

            server.Start();
            server.ClientConnected += (s, e) => go.Set();
            var client = new ClientSideConnection(fmt1);

            client.Start("127.0.0.1", 1025);
            var ok = go.WaitOne(500);

            Assert.IsTrue(ok);
            var go2 = new AutoResetEvent(false);

            client.MessageReceived += (s, e) =>
            {
                if (e is Echo)
                {
                    go2.Set();
                }
            };

            server.Connections.First().SendMessage(new Echo());
            var ok2 = go2.WaitOne(500);

            Assert.IsTrue(ok2);
        }