public void When_sending_an_explicit_delete_with_string_and_cancellation()
        {
            using var handler        = new DelayedResponseHandler(5.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            var cts = new CancellationTokenSource(1.Seconds());

            Should.Throw <TaskCanceledException>(
                async() => await client.DeleteAsync("http://example.org/api/23", cts.Token));
        }
        public void When_sending_an_explicit_get_with_string_and_completion_option_and_cancellation()
        {
            using var handler        = new DelayedResponseHandler(5.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            var cts = new CancellationTokenSource(1.Seconds());

            Should.Throw <TaskCanceledException>(
                async() => await client.GetAsync("http://example.org/api/18", HttpCompletionOption.ResponseContentRead, cts.Token));
        }
        public void When_sending_an_explicit_post_with_uri_and_cancellation()
        {
            using var handler        = new DelayedResponseHandler(5.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            var cts = new CancellationTokenSource(1.Seconds());

            Should.Throw <TaskCanceledException>(
                async() => await client.PostAsync(new Uri("http://example.org/api/9"), new MultipartFormDataContent(), cts.Token));
        }
Exemple #4
0
 public void When_sending_an_explicit_get_with_uri_and_cancellation()
 {
     using (var handler = new DelayedResponseHandler(5.Seconds()))
         using (IRestClient client = new RestClient(handler: handler))
         {
             var cts = new CancellationTokenSource(1.Seconds());
             Should.Throw <TaskCanceledException>(
                 async() => await client.GetAsync(new Uri("http://example.org/api/13"), cts.Token));
         }
 }
        public void When_sending_a_post_which_times_out()
        {
            var timeout  = 3.Seconds();
            var endpoint = new Uri("http://example.org/api/42");

            using var handler        = new DelayedResponseHandler(10.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            Should.Throw <TaskCanceledException>(
                async() => await client.PostAsync(endpoint, new MultipartFormDataContent(), timeout));

            Should.Throw <TaskCanceledException>(
                async() => await client.PostAsync(endpoint.OriginalString, new MultipartFormDataContent(), timeout));
        }
        public void When_sending_a_get_byte_array_which_times_out()
        {
            var timeout  = 3.Seconds();
            var endpoint = new Uri("http://example.org/api/38");

            using var handler        = new DelayedResponseHandler(10.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            Should.Throw <TaskCanceledException>(
                async() => await client.GetByteArrayAsync(endpoint, timeout));

            Should.Throw <TaskCanceledException>(
                async() => await client.GetByteArrayAsync(endpoint.OriginalString, timeout));
        }
        public void When_sending_a_request_with_cancellation()
        {
            using var handler        = new DelayedResponseHandler(5.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Get, RequestUri = new Uri("http://example.org/api/25")
            };

            var cts = new CancellationTokenSource(1.Seconds());

            Should.Throw <TaskCanceledException>(async() => await client.SendAsync(request, cts.Token));
        }
Exemple #8
0
        public void When_sending_a_delete_which_times_out()
        {
            var timeout  = 3.Seconds();
            var endpoint = new Uri("http://example.org/api/40");

            using (var handler = new DelayedResponseHandler(10.Seconds()))
                using (IRestClient client = new RestClient(handler: handler))
                {
                    Should.Throw <TaskCanceledException>(
                        async() => await client.DeleteAsync(endpoint, timeout));

                    Should.Throw <TaskCanceledException>(
                        async() => await client.DeleteAsync(endpoint.OriginalString, timeout));
                }
        }
        public void When_sending_a_request_then_cancelling_all_pending_requests()
        {
            using var handler        = new DelayedResponseHandler(5.Seconds());
            using IRestClient client = new RestClient(handler: handler);
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Get, RequestUri = new Uri("http://example.org/api/26")
            };

            var copy = client;

#pragma warning disable 4014
            Task.Delay(1.Seconds()).ContinueWith(_ => copy.CancelPendingRequests());
#pragma warning restore 4014
            Should.Throw <TaskCanceledException>(async() => await client.SendAsync(request));
        }