コード例 #1
0
        public async Task SendMessageAsync_With_Cancellation()
        {
            // kill the server to force client hang while sending
            _server.Dispose();

            // send the message to server
            var message = new Message();

            FillMemory(message);
            using var cts = new CancellationTokenSource();
            var sendMessageAsyncTask = _client.SendMessageAsync(message, cts.Token);

            // cancel the operation and wait for it to complete with error
            cts.Cancel();
            Func <Task> act = async() => await sendMessageAsyncTask;
            await act.Should().ThrowAsync <OperationCanceledException>();
        }
コード例 #2
0
 public void Dispose()
 {
     _server?.Dispose();
     _client?.Dispose();
 }
コード例 #3
0
 public void Dispose()
 {
     _socket?.Dispose();
 }