public async Task SendAsync_Timeout_Causes_Cancellation() { // arrange var sut = new WebSocketTextChannel(this.webSocketMock.Object, TimeSpan.Zero); _ = this.webSocketMock.Setup(ws => ws.SendAsync(It.IsAny <ArraySegment <byte> >(), It.IsAny <WebSocketMessageType>(), It.IsAny <bool>(), It.Is((CancellationToken ct) => ct.IsCancellationRequested))) .Throws(new OperationCanceledException()); await using (UseProcessSendQueueListener(sut)) { // act async Task Act() => await sut.SendAsync("foo", CancellationToken.None); // assert _ = await Assert.ThrowsAsync <TaskCanceledException>(Act); } }
public WebSocketTextChannelTests() { this.webSocketMock = new Mock <WebSocket>(); this.sut = new WebSocketTextChannel(this.webSocketMock.Object, Timeout.InfiniteTimeSpan); }
public ProcessSendQueueListener(WebSocketTextChannel webSocketTextChannel) { this.cts = new CancellationTokenSource(); this.webSocketTextChannelListenTask = webSocketTextChannel.ProcessSendQueueAsync(cts.Token); }
private IAsyncDisposable UseProcessSendQueueListener(WebSocketTextChannel webSocketTextChannel = null) => new ProcessSendQueueListener(webSocketTextChannel ?? this.sut);