public void AttemptsFiveTimesOnError() { var packageId = "FakePackageId"; var version = new NuGetVersion(1, 2, 3); var feedUri = new Uri("http://www.myget.org"); var feedCredentials = new CredentialCache(); var targetFilePath = "FakeTargetFilePath"; var calledCount = 0; Assert.Throws <Exception>(() => { //total attempts is initial attempt + 4 retries var retryTracker = new RetryTracker(maxRetries: 4, timeLimit: null, retryInterval: new RetryInterval(100, 150, 1)); var downloader = new NuGetPackageDownloader(retryTracker); downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, targetFilePath, (arg1, arg2, arg3, arg4, arg5) => { calledCount++; throw new ApplicationException("Expected exception from test"); }); }); Assert.That(calledCount, Is.EqualTo(5)); }
public void AttemptsOnlyOnceIfSuccessful() { var packageId = "FakePackageId"; var version = new NuGetVersion(1, 2, 3); var feedUri = new Uri("http://www.myget.org"); var feedCredentials = new CredentialCache(); var targetFilePath = "FakeTargetFilePath"; var calledCount = 0; var downloader = new NuGetPackageDownloader(); downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, targetFilePath, (arg1, arg2, arg3, arg4, arg5) => { calledCount++; }); Assert.That(calledCount, Is.EqualTo(1)); }
public void AttemptsOnlyOnceIfSuccessful() { var packageId = "FakePackageId"; var version = VersionFactory.CreateSemanticVersion(1, 2, 3); var feedUri = new Uri("http://www.myget.org"); var feedCredentials = new CredentialCache(); var targetFilePath = "FakeTargetFilePath"; var filesystem = Substitute.For <ICalamariFileSystem>(); var calledCount = 0; var downloader = new NuGetPackageDownloader(filesystem); downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, targetFilePath, maxDownloadAttempts: 5, downloadAttemptBackoff: TimeSpan.Zero, action: (arg1, arg2, arg3, arg4, arg5) => { calledCount++; }); Assert.That(calledCount, Is.EqualTo(1)); }
public int AttemptsTheRightNumberOfTimesOnError(int maxDownloadAttempts) { var packageId = "FakePackageId"; var version = new NuGetVersion(1, 2, 3); var feedUri = new Uri("http://www.myget.org"); var feedCredentials = new CredentialCache(); var targetFilePath = "FakeTargetFilePath"; var calledCount = 0; Assert.Throws <Exception>(() => { var downloader = new NuGetPackageDownloader(); downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, targetFilePath, maxDownloadAttempts: maxDownloadAttempts, downloadAttemptBackoff: TimeSpan.Zero, action: (arg1, arg2, arg3, arg4, arg5) => { calledCount++; throw new Exception("Expected exception from test: simulate download failing"); }); }); return(calledCount); }