Esempio n. 1
0
        public void AddInQueueShouldDoIt()
        {
            // Arrange
            var messages = _messageCreator.CreateMessages(_messageInitializer);

            // Act
            _messageCreator.AddInQueue(messages, 0);

            // Assert
            _networkMock.Verify(n => n.AddInQueue(It.IsAny <Message>(), It.IsAny <uint>()),
                                Times.Exactly(messages.Length));
        }
Esempio n. 2
0
        private void HandleGeneralMessage(Message message)
        {
            var receiver = _network.GetNodeById(message.ReceiverId);

            if (receiver.ReceivedMessages
                .Where(m => m.MessageType == MessageType.General)
                .Count(m => m.ParentId == message.ParentId)
                == message.PackagesCount)
            {
                var response = (Message[])message.Data;
                _generalMessageCreator.AddInQueue(response, receiver.Id);
            }

            _generalMessageCreator.RemoveFromQueue(new[] { message }, receiver.Id);
        }
Esempio n. 3
0
        private void CreateRandomMessages(Node sender, Node receiver)
        {
            var messageInitializer = CreateMessageInitializer(sender.Id, receiver.Id);

            var messages = _messageCreator.CreateMessages(messageInitializer);

            if (messages != null)
            {
                _messageCreator.AddInQueue(messages, messages.First().SenderId);

                LastGeneratedMessage = messages.LastOrDefault();
            }
        }
Esempio n. 4
0
        private void MessageCreate(MessageInitializer messageInitializer)
        {
            var messages = _messageCreator?.CreateMessages(messageInitializer);

            if (messages != null)
            {
                var senderId = messageInitializer.SenderId;
                _messageCreator.AddInQueue(messages, senderId);
            }
            else
            {
                throw new MessageException("Message Cannot Be Created");
            }
        }
Esempio n. 5
0
        private void HandleSendingRequest(Message request)
        {
            var responseInitializer = new MessageInitializer
            {
                ReceiverId  = request.SenderId,
                SenderId    = request.ReceiverId,
                MessageType = MessageType.PositiveSendingResponse,
                Data        = request.Data
            };

            var responses = _positiveResponseMessageCreator.CreateMessages(responseInitializer);

            foreach (var response in responses)
            {
                response.ParentId = request.ParentId;
            }

            _positiveResponseMessageCreator.AddInQueue(responses, request.ReceiverId);
        }
Esempio n. 6
0
        private void UpdateResponsesByRequest(Message[] responses, Message request)
        {
            foreach (var response in responses)
            {
                response.ParentId = request.ParentId;
                response.Data     = new[] { request };

                response.Route = response.Route
                                 .Except(request.Route)
                                 .ToArray();

                if (response.Route.Length == 0)
                {
                    response.Route = new[] { request.Route.First() };
                    _messageHandler.HandleMessage(response);
                }
                else
                {
                    _negativeResponseMessageCreator.AddInQueue(new[] { response }, request.LastTransferNodeId);
                }
            }
        }