OpenConnection() private method

private OpenConnection ( IConnection connection, string data, CancellationToken disconnectToken, bool reconnecting ) : void
connection IConnection
data string
disconnectToken System.Threading.CancellationToken
reconnecting bool
return void
Beispiel #1
0
        public void CancelledTaskHandledinServerSentEvents()
        {
            var tcs = new TaskCompletionSource<IResponse>();
            var wh = new TaskCompletionSource<Exception>();

            tcs.TrySetCanceled();

            var httpClient = new Mock<Microsoft.AspNet.SignalR.Client.Http.IHttpClient>();
            var connection = new Mock<Microsoft.AspNet.SignalR.Client.IConnection>();

            httpClient.Setup(c => c.Get(It.IsAny<string>(),
                It.IsAny<Action<Client.Http.IRequest>>(), It.IsAny<bool>()))
                .Returns(tcs.Task);

            connection.SetupGet(c => c.ConnectionToken).Returns("foo");

            var sse = new ServerSentEventsTransport(httpClient.Object);
            sse.OpenConnection(connection.Object, (ex) =>
            {
                wh.TrySetResult(ex);
            });

            Assert.True(wh.Task.Wait(TimeSpan.FromSeconds(5)));
            Assert.IsType(typeof(OperationCanceledException), wh.Task.Result);
        }