public void StartExceptionStopsAutoTransportFallback() { var errorTcs = new TaskCompletionSource <IResponse>(); errorTcs.SetException(new StartException()); var failingTransport = new Mock <IClientTransport>(); failingTransport.Setup(t => t.Start(It.IsAny <IConnection>(), It.IsAny <string>(), CancellationToken.None)) .Returns(errorTcs.Task) .Verifiable(); var unusedTransport = new Mock <IClientTransport>(); var transports = new List <IClientTransport>(); transports.Add(failingTransport.Object); transports.Add(unusedTransport.Object); var autoTransport = new AutoTransport(new DefaultHttpClient(), transports); var startTask = autoTransport.Start(new Connection("http://foo"), string.Empty, CancellationToken.None); failingTransport.Verify(); unusedTransport.Verify(t => t.Start(It.IsAny <IConnection>(), It.IsAny <string>(), CancellationToken.None), Times.Never()); Assert.IsType(typeof(StartException), startTask.Exception.InnerException); }
public async Task CancelledTaskHandledinAutoTransport() { var tcs = new TaskCompletionSource <IResponse>(); tcs.TrySetCanceled(); var transport = new Mock <IClientTransport>(); transport.Setup(t => t.Start(It.IsAny <IConnection>(), It.IsAny <string>(), CancellationToken.None)) .Returns(tcs.Task); var transports = new List <IClientTransport>(); transports.Add(transport.Object); var autoTransport = new AutoTransport(new DefaultHttpClient(), transports); await Assert.ThrowsAsync <OperationCanceledException>( () => autoTransport.Start(new Connection("http://foo"), string.Empty, CancellationToken.None)); }
public void CancelledTaskHandledinAutoTransport() { var tcs = new TaskCompletionSource <IResponse>(); tcs.TrySetCanceled(); var transport = new Mock <IClientTransport>(); transport.Setup(t => t.Start(It.IsAny <IConnection>(), It.IsAny <string>(), CancellationToken.None)) .Returns(tcs.Task); var transports = new List <IClientTransport>(); transports.Add(transport.Object); var autoTransport = new AutoTransport(new DefaultHttpClient(), transports); var task = autoTransport.Start(new Connection("http://foo"), string.Empty, CancellationToken.None); Assert.IsType(typeof(OperationCanceledException), task.Exception.InnerException); }
public async Task WebSocketsTriedByAutoTransportIfNegotiateIsNotCalled() { var fallbackTransport = new Mock <IClientTransport>(); var webSocketTransport = new Mock <IClientTransport>(); webSocketTransport.Setup(m => m.Name).Returns(new WebSocketTransport().Name); var transports = new List <IClientTransport>() { webSocketTransport.Object, fallbackTransport.Object, }; var autoTransport = new AutoTransport(null, transports); await autoTransport.Start(null, string.Empty, CancellationToken.None).OrTimeout(); webSocketTransport.Verify(m => m.Start(null, string.Empty, CancellationToken.None), Times.Once()); fallbackTransport.Verify(m => m.Start(null, string.Empty, CancellationToken.None), Times.Never()); }