public void TestCancel() { // Prepare a very slow download of the file and monitor for a cancellation exception Server.Slow = true; var download = new DownloadMemory(Server.FileUri); bool exceptionThrown = false; var cancellationTokenSource = new CancellationTokenSource(); var downloadThread = new Thread(() => { try { download.Run(cancellationTokenSource.Token); } catch (OperationCanceledException) { exceptionThrown = true; } }); // Start and then cancel the download downloadThread.Start(); Thread.Sleep(100); cancellationTokenSource.Cancel(); downloadThread.Join(); exceptionThrown.Should().BeTrue(because: "Should throw OperationCanceledException"); }
public void TestRun() { // Download the file var download = new DownloadMemory(Server.FileUri); download.Run(); // Ensure the download was successful and the file is identical download.State.Should().Be(TaskState.Complete); download.GetData().Should().Equal(GetTestFileStream().ToArray()); }
/// <inheritdoc/> public Catalog DownloadCatalog(FeedUri source) { #region Sanity checks if (source == null) throw new ArgumentNullException("source"); #endregion if (source.IsFile) return XmlStorage.LoadXml<Catalog>(source.LocalPath); var download = new DownloadMemory(source); _handler.RunTask(download); var data = download.GetData(); _trustManager.CheckTrust(data, source); return XmlStorage.LoadXml<Catalog>(new MemoryStream(data)); }
/// <summary> /// Downloads and imports a remote key file. /// </summary> /// <exception cref="WebException">The key file could not be downloaded from the internet.</exception> /// <exception cref="SignatureException">The downloaded key file is damaged.</exception> /// <exception cref="IOException">A problem occurs while writing trust configuration.</exception> /// <exception cref="UnauthorizedAccessException">Write access to the trust configuration is not permitted.</exception> private void DownloadKey([NotNull] Uri keyUri) { var download = new DownloadMemory(keyUri); _handler.RunTask(download); try { _openPgp.ImportKey(download.GetData()); } #region Error handling catch (InvalidDataException ex) { // Wrap exception since only certain exception types are allowed throw new SignatureException(ex.Message, ex); } #endregion }
private void Download(FeedUri feedUri) { SetLastCheckAttempt(feedUri); try { var download = new DownloadMemory(feedUri); _handler.RunTask(download); ImportFeed(download.GetData(), feedUri); } catch (WebException ex) { if (feedUri.IsLoopback) throw; Log.Warn(string.Format(Resources.FeedDownloadError, feedUri) + " " + Resources.TryingFeedMirror); try { var download = new DownloadMemory(GetMirrorUrl(feedUri)); _handler.RunTask(download); ImportFeed(download.GetData(), feedUri); } catch (WebException) { // Report the original problem instead of mirror errors ex.Rethrow(); } } }
public void TestIncorrectSize() { var download = new DownloadMemory(Server.FileUri, bytesTotal: 1024); download.Invoking(x => x.Run()).ShouldThrow<WebException>(); }
public void TestFileMissing() { var download = new DownloadMemory(new Uri(Server.ServerUri, "wrong")); download.Invoking(x => x.Run()).ShouldThrow<WebException>(); }
public void TestIncorrectSize() { var download = new DownloadMemory(Server.FileUri, bytesTotal: 1024); download.Invoking(x => x.Run()).ShouldThrow <WebException>(); }
public void TestFileMissing() { var download = new DownloadMemory(new Uri(Server.ServerUri, "wrong")); download.Invoking(x => x.Run()).ShouldThrow <WebException>(); }