Esempio n. 1
0
        public void EncodeDecode()
        {
            ClientFrameCodec codec = ClientFrameCodec.Instance;

            var message = new NotifyDeliver();
            message.attributes.Add("string", BigString());
            message.attributes.Add("blob", new byte[1024 * 1024]);

            var stream = new MemoryStream();

            codec.Encode(message, stream);
            stream.Position = 0;
            NotifyDeliver resMsg = (NotifyDeliver)codec.Decode(stream);

            Assert.AreEqual(message.attributes["string"], resMsg.attributes["string"]);
            Assert.AreEqual(((byte[])message.attributes["blob"]).Length,
                          ((byte[])resMsg.attributes["blob"]).Length);
        }
Esempio n. 2
0
        public void TestConnection()
        {
            AutoResetEvent evt = new AutoResetEvent(false);
            bool success = false;

            int port = 4000 + new Random().Next(500);
            ElvinListener con = new ElvinListener();

            var m = new NotifyDeliver();
            m.attributes.Add("string", BigString());
            m.attributes.Add("blob", new byte[1024 * 1024]);

            con.MessageReceived += (sender, e) =>
                {
                    NotifyDeliver rcvd = (NotifyDeliver) e.Message;

                    Assert.AreEqual(m.attributes["string"], rcvd.attributes["string"]);
                    Assert.AreEqual(((byte[])rcvd.attributes["blob"]).Length,
                                  ((byte[])m.attributes["blob"]).Length);

                    success = true;
                    evt.Set();
                };

            con.Listen(IPAddress.Parse("127.0.0.1"), port);

               // client
            ElvinConnector client = new ElvinConnector();
            client.Connect("127.0.0.1", port);
            client.Send(m);
            //con.Send(m, "127.0.0.1", port);

            // wait max. 3 seconds
            evt.WaitOne(3000);

            client.Close();
            con.Stop();

            if (!success)
            {
                Assert.Fail("Connection was unsuccessful");
            }
        }