Пример #1
0
        public void SendMessageArrayTest()
        {
            SystemInformation info = new SystemInformation();

            info.CountCore          = 4;
            info.PasswordsPerSecond = 100000;


            Agent agentOne   = new Agent(0, info, @".\private$\SendMessageArrayTestSend1", @".\private$\SendMessageArrayTestReceive1");
            Agent agentTwo   = new Agent(0, info, @".\private$\SendMessageArrayTestSend2", @".\private$\SendMessageArrayTestReceive2");
            Agent agentThree = new Agent(0, info, @".\private$\SendMessageArrayTestSend3", @".\private$\SendMessageArrayTestReceive3");

            if (!MessageQueue.Exists(agentOne.QueueReceiveName))
            {
                MessageQueue.Create(agentOne.QueueReceiveName);
            }

            if (!MessageQueue.Exists(agentTwo.QueueReceiveName))
            {
                MessageQueue.Create(agentTwo.QueueReceiveName);
            }

            if (!MessageQueue.Exists(agentThree.QueueReceiveName))
            {
                MessageQueue.Create(agentThree.QueueReceiveName);
            }

            agentOne.SetConnect();
            agentTwo.SetConnect();
            agentThree.SetConnect();

            Communication.Message testMessage = new Communication.Message(0, 0);
            PingMessage           pingMessage = new Communication.PingMessage(0, 0);

            Communication.Message[] arrayMessage = { testMessage, pingMessage };

            List <Agent> agentList = new List <Agent>()
            {
                agentOne, agentTwo, agentThree
            };

            ProcessingMessage.SendMessageArray(arrayMessage, agentList);

            foreach (var itemAgent in agentList)
            {
                var messageObj = itemAgent.QueueReceive.Receive();
                Communication.Message message = (Communication.Message)messageObj.Body;
                Assert.AreEqual(message.TypeMessage, (int)EnumTypeMessage.Message);

                messageObj = itemAgent.QueueReceive.Receive();
                message    = (Communication.Message)messageObj.Body;
                Assert.AreEqual(message.TypeMessage, (int)EnumTypeMessage.PingMessage);
            }

            MessageQueue.Delete(@".\private$\SendMessageArrayTestReceive1");
            MessageQueue.Delete(@".\private$\SendMessageArrayTestReceive2");
            MessageQueue.Delete(@".\private$\SendMessageArrayTestReceive3");
        }