public void CanceledBeforeResponse()
        {
            IWebClient client           = new WebClientWrapper();
            Uri        uri              = new Uri("http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso");
            CancellationTokenSource cts = new CancellationTokenSource(100);

            Directory.CreateDirectory(TestOutputPath);
            string filePath = Path.Combine(TestOutputPath, "CanceledBeforeResponse.iso");

            try
            {
                using (IWebResponseMessage response = client.GetAsync(uri, cts.Token).Result)
                {
                    if (!response.IsSuccessStatusCode)
                    {
                        Assert.Fail($"Error getting response from {uri}: {response.ReasonPhrase}");
                    }
                    Assert.Fail("Didn't throw exception");
                }
            }
            catch (AggregateException ex)
            {
                if (!(ex.InnerException is OperationCanceledException))
                {
                    Assert.Fail("Wrong exception thrown.");
                }
            }
            catch (Exception)
            {
                Assert.Fail("Wrong exception thrown.");
            }
            cts.Dispose();
            client.Dispose();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing || _disposed)
            {
                return;
            }

            _searchWebClient.Dispose();
            _packageDownloader.Dispose();
            _searchCancellationTokenSource.Dispose();
            _downloadCancellationTokenSource.Dispose();
            _downloadResetEvent.Dispose();
            _disposed = true;
        }