public void should_handle_directory_events_during_the_register()
        {
            var otherPeerDescriptor = _otherPeer.ToPeerDescriptor(true, typeof(FakeCommand), typeof(FakeEvent));
            otherPeerDescriptor.TimestampUtc = default(DateTime);
            var peerStarted = new PeerStarted(otherPeerDescriptor);
            var peerStopped = new PeerStopped(_otherPeer);

            _bus.AddHandler<RegisterPeerCommand>(x =>
            {
                var peerDescriptor = _otherPeer.ToPeerDescriptor(true);
                _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow.AddTicks(1), new MessageTypeId(typeof(FakeEvent)), BindingKey.Empty));
                return new RegisterPeerResponse(new[] { peerDescriptor });
            });

            var task = Task.Run(() =>
            {
                for (var i = 0; i < 10000; i++)
                {
                    _directory.Handle(peerStarted);
                    _directory.Handle(peerStopped);
                }
            });

            Wait.Until(() => task.Status == TaskStatus.Running || task.Status == TaskStatus.RanToCompletion, 1.Second());

           _directory.Register(_bus, _self, otherPeerDescriptor.Subscriptions );

            task.Wait(1.Second());
        }
        public void should_add_started_peers()
        {
            var updatedPeerId = default(PeerId);
            var updateAction = PeerUpdateAction.Decommissioned;
            _directory.PeerUpdated += (id, action) =>
                {
                    updatedPeerId = id;
                    updateAction = action;
                };
            var clientPeerDescriptor = _otherPeer.ToPeerDescriptor(true, typeof(FakeEvent));
            var peerStarted = new PeerStarted(clientPeerDescriptor);

            _directory.Handle(peerStarted);

            var peerHandlingMessage = _directory.GetPeersHandlingMessage(new FakeEvent(0)).Single();
            peerHandlingMessage.Id.ShouldEqual(clientPeerDescriptor.Peer.Id);
            peerHandlingMessage.EndPoint.ShouldEqual(clientPeerDescriptor.Peer.EndPoint);
            peerHandlingMessage.IsUp.ShouldBeTrue();
            updatedPeerId.ShouldEqual(_otherPeer.Id);
            updateAction.ShouldEqual(PeerUpdateAction.Started);
        }
        public void should_get_all_peer_descriptor()
        {
            var clientPeerDescriptor = _otherPeer.ToPeerDescriptor(true, typeof(FakeEvent));
            var peerStarted = new PeerStarted(clientPeerDescriptor);

            _directory.Handle(peerStarted);

            _directory.GetPeerDescriptors().Count().ShouldEqual(1);
        }
        public void should_get_peer_by_id()
        {
            var clientPeerDescriptor = _otherPeer.ToPeerDescriptor(true);
            var peerStarted = new PeerStarted(clientPeerDescriptor);
            _directory.Handle(peerStarted);

            var peerDescriptor = _directory.GetPeerDescriptor(clientPeerDescriptor.Peer.Id);

            peerDescriptor.ShouldHaveSamePropertiesAs(clientPeerDescriptor);
        }