Пример #1
0
        public void AddMessageInStartShouldAddMessageOnZeroPosition()
        {
            // Arrange
            var newMessage = new Message
            {
                DataSize    = 1,
                ServiceSize = 1,
                Route       = new Channel[0]
            };

            _messageQueueHandler.AppendMessage(newMessage);

            var initialSize = _messageQueueHandler.MessagesCount;

            // Act
            _messageQueueHandler.AddMessageInStart(_message);

            var resultSize = _messageQueueHandler.MessagesCount;

            // Assert
            Assert.That(resultSize - initialSize, Is.EqualTo(1));
            Assert.That(_messageQueueHandler.Messages.First(), Is.EqualTo(_message));
        }
Пример #2
0
        private void ReplaceMessageInChannel(Channel channel, Message message,
                                             IMessageQueueHandler messageQueueHandler)
        {
            var isSuccess = TryMoveMessageToChannel(channel, message);

            messageQueueHandler.RemoveMessage(message);

            if (!isSuccess)
            {
                if (message.MessageType == MessageType.SendingRequest)
                {
                    var sender = _network.GetNodeById(message.LastTransferNodeId);
                    _messageReceiver.HandleReceivedMessage(sender, message);
                }
                else
                {
                    messageQueueHandler.AddMessageInStart(message);
                }
            }
            else
            {
                _handledMessagesInNode.Add(message);
            }
        }