Exemplo n.º 1
0
        public async Task GetAsync_Cancel_CancellationTokenPropagates()
        {
            var cts = new CancellationTokenSource();
            cts.Cancel();
            try
            {
                var handler = new SendAsyncWinHttpMockHandler();
                Task <HttpResponseMessage> task = handler.SendAsyncPublic(new HttpRequestMessage(HttpMethod.Post, HttpTestServers.RemoteGetServer), cts.Token);       
                await task;

                Assert.True(false, "Expected TaskCanceledException to be thrown.");
            }
            catch (TaskCanceledException ex)
            {
                Assert.True(cts.Token.IsCancellationRequested,
                    "Expected cancellation requested on original token.");

                Assert.True(ex.CancellationToken.IsCancellationRequested,
                    "Expected cancellation requested on token attached to exception.");
            }
        }
Exemplo n.º 2
0
        public async Task GetAsync_Cancel_CancellationTokenPropagates()
        {
            var cts = new CancellationTokenSource();

            cts.Cancel();
            try
            {
                var handler = new SendAsyncWinHttpMockHandler();
                Task <HttpResponseMessage> task = handler.SendAsyncPublic(new HttpRequestMessage(HttpMethod.Post, HttpTestServers.RemoteGetServer), cts.Token);
                await task;

                Assert.True(false, "Expected TaskCanceledException to be thrown.");
            }
            catch (TaskCanceledException ex)
            {
                Assert.True(cts.Token.IsCancellationRequested,
                            "Expected cancellation requested on original token.");

                Assert.True(ex.CancellationToken.IsCancellationRequested,
                            "Expected cancellation requested on token attached to exception.");
            }
        }