public void WhisperTest()
        {
            Action <ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Whisper;

                m.Whisper.Sequence = 123;

                m.Whisper.Content = new NetMQMessage();
                m.Whisper.Content.Append("Hello");
                m.Whisper.Content.Append("World");
            };

            Action <ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Whisper));
                Assert.That(m.Whisper.Sequence, Is.EqualTo(123));
                Assert.That(m.Whisper.Content.FrameCount, Is.EqualTo(2));
                var str1 = m.Whisper.Content[0].ConvertToString();
                Assert.That(str1, Is.EqualTo("Hello"));
                var str2 = m.Whisper.Content[1].ConvertToString();
                Assert.That(str2, Is.EqualTo("World"));
            };

            using (var client = new DealerSocket())
                using (var server = new RouterSocket())
                {
                    server.Bind("inproc://zprototestWhisper");
                    client.Connect("inproc://zprototestWhisper");

                    ZreMsg clientMessage = new ZreMsg();
                    ZreMsg serverMessage = new ZreMsg();

                    for (int i = 0; i < 2; i++)
                    {
                        // client send message to server
                        setMessage(clientMessage);
                        clientMessage.Send(client);

                        // server receive the message
                        serverMessage.Receive(server);

                        // check that message received ok
                        Assert.That(serverMessage.RoutingId, Is.Not.Null);
                        checkMessage(serverMessage);

                        // reply to client, no need to set the message, using client data
                        serverMessage.Send(server);

                        // client receive the message
                        clientMessage.Receive(client);

                        // check that message received ok
                        Assert.That(clientMessage.RoutingId, Is.Null);
                        checkMessage(clientMessage);
                    }
                }
        }
        public void LeaveTest()
        {
            Action <ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Leave;

                m.Leave.Sequence = 123;
                m.Leave.Group    = "Life is short but Now lasts for ever";
                m.Leave.Status   = 123;
            };

            Action <ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Leave));
                Assert.That(m.Leave.Sequence, Is.EqualTo(123));
                Assert.That(m.Leave.Group, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Leave.Status, Is.EqualTo(123));
            };

            using (var client = new DealerSocket())
                using (var server = new RouterSocket())
                {
                    // TODO: If I use inproc://zprototest ReSharper TestRunner fails with NetMQ.AddressAlreadyInUseException :
                    //  Cannot bind address ( inproc://zprototest ) - already in use.
                    //  But only when I run all these tests at the same time.
                    server.Bind("inproc://zprototestLeave");
                    client.Connect("inproc://zprototestLeave");

                    ZreMsg clientMessage = new ZreMsg();
                    ZreMsg serverMessage = new ZreMsg();

                    for (int i = 0; i < 2; i++)
                    {
                        // client send message to server
                        setMessage(clientMessage);
                        clientMessage.Send(client);

                        // server receive the message
                        serverMessage.Receive(server);

                        // check that message received ok
                        Assert.That(serverMessage.RoutingId, Is.Not.Null);
                        checkMessage(serverMessage);

                        // reply to client, no need to set the message, using client data
                        serverMessage.Send(server);

                        // client receive the message
                        clientMessage.Receive(client);

                        // check that message received ok
                        Assert.That(clientMessage.RoutingId, Is.Null);
                        checkMessage(clientMessage);
                    }
                }
        }
        public void JoinTest()
        {
            Action <ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Join;

                m.Join.Sequence = 123;
                m.Join.Group    = "Life is short but Now lasts for ever";
                m.Join.Status   = 123;
            };

            Action <ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Join));
                Assert.That(m.Join.Sequence, Is.EqualTo(123));
                Assert.That(m.Join.Group, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Join.Status, Is.EqualTo(123));
            };

            using (var client = new DealerSocket())
                using (var server = new RouterSocket())
                {
                    server.Bind("inproc://zprototestJoin");
                    client.Connect("inproc://zprototestJoin");

                    ZreMsg clientMessage = new ZreMsg();
                    ZreMsg serverMessage = new ZreMsg();

                    for (int i = 0; i < 2; i++)
                    {
                        // client send message to server
                        setMessage(clientMessage);
                        clientMessage.Send(client);

                        // server receive the message
                        serverMessage.Receive(server);

                        // check that message received ok
                        Assert.That(serverMessage.RoutingId, Is.Not.Null);
                        checkMessage(serverMessage);

                        // reply to client, no need to set the message, using client data
                        serverMessage.Send(server);

                        // client receive the message
                        clientMessage.Receive(client);

                        // check that message received ok
                        Assert.That(clientMessage.RoutingId, Is.Null);
                        checkMessage(clientMessage);
                    }
                }
        }
        public void PingOkTest()
        {
            Action <ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.PingOk;

                m.PingOk.Sequence = 123;
            };

            Action <ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.PingOk));
                Assert.That(m.PingOk.Sequence, Is.EqualTo(123));
            };

            using (var client = new DealerSocket())
                using (var server = new RouterSocket())
                {
                    server.Bind("inproc://zprototestPingOk");
                    client.Connect("inproc://zprototestPingOk");

                    ZreMsg clientMessage = new ZreMsg();
                    ZreMsg serverMessage = new ZreMsg();

                    for (int i = 0; i < 2; i++)
                    {
                        // client send message to server
                        setMessage(clientMessage);
                        clientMessage.Send(client);

                        // server receive the message
                        serverMessage.Receive(server);

                        // check that message received ok
                        Assert.That(serverMessage.RoutingId, Is.Not.Null);
                        checkMessage(serverMessage);

                        // reply to client, no need to set the message, using client data
                        serverMessage.Send(server);

                        // client receive the message
                        clientMessage.Receive(client);

                        // check that message received ok
                        Assert.That(clientMessage.RoutingId, Is.Null);
                        checkMessage(clientMessage);
                    }
                }
        }
        public void HelloTest()
        {
            Action <ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Hello;

                m.Hello.Sequence = 123;
                m.Hello.Endpoint = "Life is short but Now lasts for ever";
                m.Hello.Groups   = new List <string>();
                m.Hello.Groups.Add("Name: Brutus");
                m.Hello.Groups.Add("Age: 43");
                m.Hello.Status  = 123;
                m.Hello.Name    = "Life is short but Now lasts for ever";
                m.Hello.Headers = new Dictionary <string, string>();
                m.Hello.Headers.Add("Name", "Brutus");
                m.Hello.Headers.Add("Age", "43");
            };

            Action <ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Hello));
                Assert.That(m.Hello.Sequence, Is.EqualTo(123));
                Assert.That(m.Hello.Endpoint, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Hello.Groups.Count, Is.EqualTo(2));
                Assert.That(m.Hello.Groups[0], Is.EqualTo("Name: Brutus"));
                Assert.That(m.Hello.Groups[1], Is.EqualTo("Age: 43"));
                Assert.That(m.Hello.Status, Is.EqualTo(123));
                Assert.That(m.Hello.Name, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Hello.Headers.Count, Is.EqualTo(2));
                Assert.That(m.Hello.Headers["Name"], Is.EqualTo("Brutus"));
                Assert.That(m.Hello.Headers["Age"], Is.EqualTo("43"));
            };

            using (var client = new DealerSocket())
                using (var server = new RouterSocket())
                {
                    server.Bind("inproc://zprototestHello");
                    client.Connect("inproc://zprototestHello");

                    ZreMsg clientMessage = new ZreMsg();
                    ZreMsg serverMessage = new ZreMsg();

                    for (int i = 0; i < 2; i++)
                    {
                        // client send message to server
                        setMessage(clientMessage);
                        clientMessage.Send(client);

                        // server receive the message
                        serverMessage.Receive(server);

                        // check that message received ok
                        Assert.That(serverMessage.RoutingId, Is.Not.Null);
                        checkMessage(serverMessage);

                        // reply to client, no need to set the message, using client data
                        serverMessage.Send(server);

                        // client receive the message
                        clientMessage.Receive(client);

                        // check that message received ok
                        Assert.That(clientMessage.RoutingId, Is.Null);
                        checkMessage(clientMessage);
                    }
                }
        }
示例#6
0
文件: ZreMsgTests.cs 项目: NetMQ/Zyre
        public void WhisperTest()
        {
            Action<ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Whisper;

                m.Whisper.Sequence = 123;

                m.Whisper.Content = new NetMQMessage();
                m.Whisper.Content.Append("Hello");
                m.Whisper.Content.Append("World");
            };

            Action<ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Whisper));
                Assert.That(m.Whisper.Sequence, Is.EqualTo(123));
                Assert.That(m.Whisper.Content.FrameCount, Is.EqualTo(2));
                var str1 = m.Whisper.Content[0].ConvertToString();
                Assert.That(str1, Is.EqualTo("Hello"));
                var str2 = m.Whisper.Content[1].ConvertToString();
                Assert.That(str2, Is.EqualTo("World"));
            };

            using (var client = new DealerSocket())
            using (var server = new RouterSocket())
            {
                server.Bind("inproc://zprototestWhisper");
                client.Connect("inproc://zprototestWhisper");

                ZreMsg clientMessage = new ZreMsg();
                ZreMsg serverMessage = new ZreMsg();

                for (int i = 0; i < 2; i++)
                {
                    // client send message to server
                    setMessage(clientMessage);
                    clientMessage.Send(client);

                    // server receive the message
                    serverMessage.Receive(server);

                    // check that message received ok
                    Assert.That(serverMessage.RoutingId, Is.Not.Null);
                    checkMessage(serverMessage);

                    // reply to client, no need to set the message, using client data
                    serverMessage.Send(server);

                    // client receive the message
                    clientMessage.Receive(client);

                    // check that message received ok
                    Assert.That(clientMessage.RoutingId, Is.Null);
                    checkMessage(clientMessage);
                }
            }
        }
示例#7
0
文件: ZreMsgTests.cs 项目: NetMQ/Zyre
        public void PingOkTest()
        {
            Action<ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.PingOk;

                m.PingOk.Sequence = 123;
            };

            Action<ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.PingOk));
                Assert.That(m.PingOk.Sequence, Is.EqualTo(123));
            };

            using (var client = new DealerSocket())
            using (var server = new RouterSocket())
            {
                server.Bind("inproc://zprototestPingOk");
                client.Connect("inproc://zprototestPingOk");

                ZreMsg clientMessage = new ZreMsg();
                ZreMsg serverMessage = new ZreMsg();

                for (int i = 0; i < 2; i++)
                {
                    // client send message to server
                    setMessage(clientMessage);
                    clientMessage.Send(client);

                    // server receive the message
                    serverMessage.Receive(server);

                    // check that message received ok
                    Assert.That(serverMessage.RoutingId, Is.Not.Null);
                    checkMessage(serverMessage);

                    // reply to client, no need to set the message, using client data
                    serverMessage.Send(server);

                    // client receive the message
                    clientMessage.Receive(client);

                    // check that message received ok
                    Assert.That(clientMessage.RoutingId, Is.Null);
                    checkMessage(clientMessage);
                }
            }
        }
示例#8
0
文件: ZreMsgTests.cs 项目: NetMQ/Zyre
        public void LeaveTest()
        {
            Action<ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Leave;

                m.Leave.Sequence = 123;
                m.Leave.Group = "Life is short but Now lasts for ever";
                m.Leave.Status = 123;
            };

            Action<ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Leave));
                Assert.That(m.Leave.Sequence, Is.EqualTo(123));
                Assert.That(m.Leave.Group, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Leave.Status, Is.EqualTo(123));
            };

            using (var client = new DealerSocket())
            using (var server = new RouterSocket())
            {
                //  Cannot bind address ( inproc://zprototest ) - already in use.
                //  But only when I run all these tests at the same time.
                server.Bind("inproc://zprototestLeave");
                client.Connect("inproc://zprototestLeave");

                ZreMsg clientMessage = new ZreMsg();
                ZreMsg serverMessage = new ZreMsg();

                for (int i = 0; i < 2; i++)
                {
                    // client send message to server
                    setMessage(clientMessage);
                    clientMessage.Send(client);

                    // server receive the message
                    serverMessage.Receive(server);

                    // check that message received ok
                    Assert.That(serverMessage.RoutingId, Is.Not.Null);
                    checkMessage(serverMessage);

                    // reply to client, no need to set the message, using client data
                    serverMessage.Send(server);

                    // client receive the message
                    clientMessage.Receive(client);

                    // check that message received ok
                    Assert.That(clientMessage.RoutingId, Is.Null);
                    checkMessage(clientMessage);
                }
            }
        }
示例#9
0
文件: ZreMsgTests.cs 项目: NetMQ/Zyre
        public void HelloTest()
        {
            Action<ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Hello;

                m.Hello.Sequence = 123;
                m.Hello.Endpoint = "Life is short but Now lasts for ever";
                m.Hello.Groups = new List<string>();
                m.Hello.Groups.Add("Name: Brutus");
                m.Hello.Groups.Add("Age: 43");
                m.Hello.Status = 123;
                m.Hello.Name = "Life is short but Now lasts for ever";
                m.Hello.Headers = new Dictionary<string, string>();
                m.Hello.Headers.Add("Name", "Brutus");
                m.Hello.Headers.Add("Age", "43");
            };

            Action<ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Hello));
                Assert.That(m.Hello.Sequence, Is.EqualTo(123));
                Assert.That(m.Hello.Endpoint, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Hello.Groups.Count, Is.EqualTo(2));
                Assert.That(m.Hello.Groups[0], Is.EqualTo("Name: Brutus"));
                Assert.That(m.Hello.Groups[1], Is.EqualTo("Age: 43"));
                Assert.That(m.Hello.Status, Is.EqualTo(123));
                Assert.That(m.Hello.Name, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Hello.Headers.Count, Is.EqualTo(2));
                Assert.That(m.Hello.Headers["Name"], Is.EqualTo("Brutus"));
                Assert.That(m.Hello.Headers["Age"], Is.EqualTo("43"));
            };

            using (var client = new DealerSocket())
            using (var server = new RouterSocket())
            {
                server.Bind("inproc://zprototestHello");
                client.Connect("inproc://zprototestHello");

                ZreMsg clientMessage = new ZreMsg();
                ZreMsg serverMessage = new ZreMsg();

                for (int i = 0; i < 2; i++)
                {
                    // client send message to server
                    setMessage(clientMessage);
                    clientMessage.Send(client);

                    // server receive the message
                    serverMessage.Receive(server);

                    // check that message received ok
                    Assert.That(serverMessage.RoutingId, Is.Not.Null);
                    checkMessage(serverMessage);

                    // reply to client, no need to set the message, using client data
                    serverMessage.Send(server);

                    // client receive the message
                    clientMessage.Receive(client);

                    // check that message received ok
                    Assert.That(clientMessage.RoutingId, Is.Null);
                    checkMessage(clientMessage);
                }
            }
        }
示例#10
0
文件: ZreMsgTests.cs 项目: NetMQ/Zyre
        public void JoinTest()
        {
            Action<ZreMsg> setMessage = m =>
            {
                m.Id = ZreMsg.MessageId.Join;

                m.Join.Sequence = 123;
                m.Join.Group = "Life is short but Now lasts for ever";
                m.Join.Status = 123;
            };

            Action<ZreMsg> checkMessage = m =>
            {
                Assert.That(m.Id, Is.EqualTo(ZreMsg.MessageId.Join));
                Assert.That(m.Join.Sequence, Is.EqualTo(123));
                Assert.That(m.Join.Group, Is.EqualTo("Life is short but Now lasts for ever"));
                Assert.That(m.Join.Status, Is.EqualTo(123));
            };

            using (var client = new DealerSocket())
            using (var server = new RouterSocket())
            {
                server.Bind("inproc://zprototestJoin");
                client.Connect("inproc://zprototestJoin");

                ZreMsg clientMessage = new ZreMsg();
                ZreMsg serverMessage = new ZreMsg();

                for (int i = 0; i < 2; i++)
                {
                    // client send message to server
                    setMessage(clientMessage);
                    clientMessage.Send(client);

                    // server receive the message
                    serverMessage.Receive(server);

                    // check that message received ok
                    Assert.That(serverMessage.RoutingId, Is.Not.Null);
                    checkMessage(serverMessage);

                    // reply to client, no need to set the message, using client data
                    serverMessage.Send(server);

                    // client receive the message
                    clientMessage.Receive(client);

                    // check that message received ok
                    Assert.That(clientMessage.RoutingId, Is.Null);
                    checkMessage(clientMessage);
                }
            }
        }