public void Setup()
        {
            InnerTransport = new TestTransport(Self.EndPoint);

            var configuration = new Mock <IBusConfiguration>();

            configuration.Setup(x => x.IsPersistent).Returns(IsPersistent);
            configuration.Setup(x => x.StartReplayTimeout).Returns(TimeSpan.FromMinutes(60));

            PeerDirectory = new Mock <IPeerDirectory>();
            PeerDirectory.Setup(dir => dir.GetPeersHandlingMessage(MessageBinding.Default <PersistMessageCommand>())).Returns(new[] { PersistencePeer });
            PeerDirectory.Setup(dir => dir.GetPeersHandlingMessage(It.IsAny <StartMessageReplayCommand>())).Returns(new[] { PersistencePeer });
            PeerDirectory.Setup(dir => dir.GetPeersHandlingMessage(It.IsAny <PersistMessageCommand>())).Returns(new[] { PersistencePeer });
            PeerDirectory.Setup(dir => dir.GetPeersHandlingMessage(It.IsAny <MessageHandled>())).Returns(new[] { PersistencePeer });
            PeerDirectory.Setup(dir => dir.IsPersistent(AnotherPersistentPeer.Id)).Returns(true);
            PeerDirectory.Setup(dir => dir.IsPersistent(AnotherNonPersistentPeer.Id)).Returns(false);

            Transport = new PersistentTransport(configuration.Object, InnerTransport, PeerDirectory.Object, new DefaultMessageSendingStrategy());
            Transport.Configure(Self.Id, "test");

            MessagesForwardedToBus     = new ConcurrentQueue <TransportMessage>();
            Transport.MessageReceived += MessagesForwardedToBus.Enqueue;

            Transport.OnRegistered();
            var startMessageReplayMessage = InnerTransport.Messages.FirstOrDefault(x => x.TransportMessage.MessageTypeId == MessageUtil.TypeId <StartMessageReplayCommand>());

            if (startMessageReplayMessage != null)
            {
                StartMessageReplayCommand        = (StartMessageReplayCommand)startMessageReplayMessage.TransportMessage.ToMessage();
                StartMessageReplayCommandTargets = startMessageReplayMessage.Targets;
            }

            InnerTransport.Messages.Clear();
        }
        private void ReplayMessagesWaitingForPersistence()
        {
            var persistencePeers = _peerDirectory.GetPeersHandlingMessage(MessageBinding.Default <PersistMessageCommand>());

            _logger.InfoFormat("Sending {0} enqueued messages to the persistence", _messagesWaitingForPersistence.Count);

            IMessage messageToSend;

            while (_messagesWaitingForPersistence.TryTake(out messageToSend))
            {
                SendToPersistenceService(messageToSend, persistencePeers);
            }
        }