public async void TestSendConnectionAsyncisOverwrittenWhenClientConnectionExisted()
        {
            var serviceConnectionManager = new TestServiceConnectionManager <TestHub>();
            var clientConnectionManager  = new ClientConnectionManager();

            var context    = new ClientConnectionContext(new OpenConnectionMessage("conn1", new Claim[] { }));
            var connection = new TestServiceConnectionPrivate();

            context.ServiceConnection = connection;
            clientConnectionManager.AddClientConnection(context);

            var manager = MockLifetimeManager(serviceConnectionManager, clientConnectionManager);

            await manager.SendConnectionAsync("conn1", "foo", new object[] { 1, 2 });

            Assert.NotNull(connection.LastMessage);
            if (connection.LastMessage is MultiConnectionDataMessage m)
            {
                Assert.Equal("conn1", m.ConnectionList[0]);
                Assert.Equal(1, m.Payloads.Count);
                Assert.True(m.Payloads.ContainsKey(MockProtocol));
                return;
            }
            Assert.True(false);
        }
Esempio n. 2
0
        public void AddClientConnection(ClientConnectionContext clientConnection)
        {
            ClientConnectionManager.AddClientConnection(clientConnection);

            if (_waitForConnectionOpen.TryGetValue(clientConnection.ConnectionId, out var tcs))
            {
                tcs.TrySetResult(clientConnection);
            }
        }
Esempio n. 3
0
            public void AddClientConnection(ClientConnectionContext clientConnection)
            {
                var tcs = _tcs.GetOrAdd(clientConnection.ConnectionId,
                                        s => new TaskCompletionSource <ClientConnectionContext>(TaskCreationOptions
                                                                                                .RunContinuationsAsynchronously));

                _ccm.AddClientConnection(clientConnection);
                tcs.SetResult(clientConnection);
            }
        public void TestAllClientConnectionsCompleted()
        {
            var manager = new ClientConnectionManager();

            var c1 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("foo", new Claim[0]));
            var c2 = new ClientConnectionContext(new Protocol.OpenConnectionMessage("bar", new Claim[0]));

            manager.AddClientConnection(c1);
            manager.AddClientConnection(c2);

            _ = RemoveConnection(manager, c1);
            _ = RemoveConnection(manager, c2);

            var expected = manager.WhenAllCompleted();
            var actual   = Task.WaitAny(
                expected,
                Task.Delay(TimeSpan.FromSeconds(1))
                );

            Assert.Equal(0, actual);
        }