private string DownloadSamplePackage(PackageId packageId, NuGetVersion version,
                                             NuGetPackageDownloader nuGetPackageDownloader)
        {
            return(ExponentialRetry.ExecuteWithRetry(
                       DownloadMostRecentSamplePackageFromPublicFeed,
                       result => result != null,
                       3,
                       () => ExponentialRetry.Timer(ExponentialRetry.Intervals),
                       "Run command while retry transient restore error")
                   .ConfigureAwait(false).GetAwaiter().GetResult());

            string DownloadMostRecentSamplePackageFromPublicFeed()
            {
                try
                {
                    return(nuGetPackageDownloader.DownloadPackageAsync(
                               packageId, version, includePreview: true,
                               packageSourceLocation: new PackageSourceLocation(
                                   sourceFeedOverrides: new[] { "https://api.nuget.org/v3/index.json" })).GetAwaiter()
                           .GetResult());
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
Пример #2
0
        private string DownloadSamplePackage(PackageId packageId)
        {
            NuGetPackageDownloader nuGetPackageDownloader = new NuGetPackageDownloader(_tempDirectory, null,
                                                                                       new MockFirstPartyNuGetPackageSigningVerifier(),
                                                                                       _logger, restoreActionConfig: new RestoreActionConfig(NoCache: true));

            return(ExponentialRetry.ExecuteWithRetry <string>(
                       action: DownloadMostRecentSamplePackageFromPublicFeed,
                       shouldStopRetry: result => result != null,
                       maxRetryCount: 3,
                       timer: () => ExponentialRetry.Timer(ExponentialRetry.Intervals),
                       taskDescription: "Run command while retry transient restore error")
                   .ConfigureAwait(false).GetAwaiter().GetResult());

            string DownloadMostRecentSamplePackageFromPublicFeed()
            {
                try
                {
                    return(nuGetPackageDownloader.DownloadPackageAsync(
                               new PackageId("Microsoft.iOS.Ref"), null, includePreview: true,
                               packageSourceLocation: new PackageSourceLocation(
                                   sourceFeedOverrides: new[] { "https://api.nuget.org/v3/index.json" })).GetAwaiter()
                           .GetResult());
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
Пример #3
0
        // https://aka.ms/netsdkinternal-certificate-rotate
        public void ItShouldHaveUpdateToDateCertificateSha()
        {
            NuGetPackageDownloader nuGetPackageDownloader = new NuGetPackageDownloader(_tempDirectory, null,
                                                                                       new MockFirstPartyNuGetPackageSigningVerifier(),
                                                                                       _logger, restoreActionConfig: new RestoreActionConfig(NoCache: true));

            var samplePackage = ExponentialRetry.ExecuteWithRetry <string>(
                action: DownloadMostRecentSamplePackageFromPublicFeed,
                shouldStopRetry: result => result != null,
                maxRetryCount: 3,
                timer: () => ExponentialRetry.Timer(ExponentialRetry.Intervals),
                taskDescription: "Run command while retry transient restore error")
                                .ConfigureAwait(false).GetAwaiter().GetResult();

            string DownloadMostRecentSamplePackageFromPublicFeed()
            {
                try
                {
                    return(nuGetPackageDownloader.DownloadPackageAsync(
                               new PackageId("Microsoft.iOS.Ref"), null, includePreview: true,
                               packageSourceLocation: new PackageSourceLocation(
                                   sourceFeedOverrides: new[] { "https://api.nuget.org/v3/index.json" })).GetAwaiter()
                           .GetResult());
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            var    firstPartyNuGetPackageSigningVerifier = new FirstPartyNuGetPackageSigningVerifier();
            string shaFromPackage = GetShaFromSamplePackage(samplePackage);

            firstPartyNuGetPackageSigningVerifier._firstPartyCertificateThumbprints.Contains(shaFromPackage).Should()
            .BeTrue(
                $"Add {shaFromPackage} to the _firstPartyCertificateThumbprints of FirstPartyNuGetPackageSigningVerifier class. More info https://aka.ms/netsdkinternal-certificate-rotate");
        }
Пример #4
0
 public NuGetPackageInstallerTests(ITestOutputHelper log) : base(log)
 {
     _tempDirectory = GetUniqueTempProjectPathEachTest();
     _logger        = new NuGetTestLogger();
     _installer     =
         new NuGetPackageDownloader(_tempDirectory, null, new MockFirstPartyNuGetPackageSigningVerifier(), _logger,
                                    restoreActionConfig: new RestoreActionConfig(NoCache: true), timer: () => ExponentialRetry.Timer(ExponentialRetry.TestingIntervals));
 }
Пример #5
0
        public void ItRetriesOnError()
        {
            var retryCount = 0;
            Func <Task <string> > action = () => {
                retryCount++;
                throw new Exception();
            };

            Assert.Throws <AggregateException>(() => ExponentialRetry.ExecuteWithRetryOnFailure <string>(action, 2, timer: () => ExponentialRetry.Timer(ExponentialRetry.TestingIntervals)).Result);

            retryCount.Should().Be(2);
        }