public void Connecting(string callerConnectionId, IClientProxy allClients)
        {
            _allClientProxy = allClients;

            bool hasOne;

            lock (_connectedIdsLockPad)
            {
                _connectedIds.Add(callerConnectionId);
                hasOne = _connectedIds.Count == 1;
            }

            if (hasOne)
            {
                _messageQueueSubscription = _messageQueueService.Receive()
                                            .Subscribe(message => _radioHubMessageDispatcher.Dispatch(message, _allClientProxy));
            }
        }
Beispiel #2
0
        public void MessageQueueService_CanSendAndReceive()
        {
            // Arrange & Act
            var cancellationTokenSource = new CancellationTokenSource(20000);
            var taskCompletionSource    = new TaskCompletionSource <Message>();

            Task.Factory.StartNew(() =>
            {
                _messageQueueService.Receive()
                .Subscribe(message => taskCompletionSource.SetResult(message));

                _messageQueueService.Send(Message.VotingMessage);
            });

            cancellationTokenSource.Token.Register(() => taskCompletionSource.TrySetCanceled(), useSynchronizationContext: false);

            var result = taskCompletionSource.Task.Result;

            // Assert
            Assert.That(result, Is.EqualTo(Message.VotingMessage));
        }