public async Task GetAllVersionsAsync_ReturnsAllVersionsAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var versions = await test.Resource.GetAllVersionsAsync(
                    test.PackageIdentity.Id,
                    test.SourceCacheContext,
                    NullLogger.Instance,
                    CancellationToken.None);

                Assert.Equal(new[]
                {
                    NuGetVersion.Parse("0.1.0"),
                    NuGetVersion.Parse("0.2.0"),
                    NuGetVersion.Parse("0.3.0"),
                    NuGetVersion.Parse("0.4.0"),
                    NuGetVersion.Parse("0.5.0"),
                    NuGetVersion.Parse("0.6.0"),
                    NuGetVersion.Parse("0.7.0"),
                    NuGetVersion.Parse("0.8.0"),
                    NuGetVersion.Parse("0.9.0"),
                    NuGetVersion.Parse("0.10.0"),
                    NuGetVersion.Parse("0.11.0"),
                    NuGetVersion.Parse("0.12.0"),
                    NuGetVersion.Parse("1.0.0"),
                    NuGetVersion.Parse("1.1.0"),
                    NuGetVersion.Parse("1.1.1"),
                    NuGetVersion.Parse("1.2.0"),
                    NuGetVersion.Parse("1.3.0"),
                    NuGetVersion.Parse("1.4.0"),
                    NuGetVersion.Parse("1.4.0.1-rc")
                }, versions);
            }
        }
        public async Task HttpFileSystemBasedFindPackageByIdResource_EnhancedHttpRetrySettings()
        {
            const int testTryCount = 7;
            TestEnvironmentVariableReader testEnvironmentVariableReader = new TestEnvironmentVariableReader(
                new Dictionary <string, string>()
            {
                [EnhancedHttpRetryHelper.IsEnabledEnvironmentVariableName]           = bool.TrueString,
                [EnhancedHttpRetryHelper.RetryCountEnvironmentVariableName]          = testTryCount.ToString(),
                [EnhancedHttpRetryHelper.DelayInMillisecondsEnvironmentVariableName] = "0"
            });

            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync(testEnvironmentVariableReader))
            {
                var exception = await Assert.ThrowsAsync <FatalProtocolException>(
                    () => test.Resource.GetPackageDownloaderAsync(
                        new PackageIdentity(id: "socketexception", version: NuGetVersion.Parse("1.2.3")),
                        test.SourceCacheContext,
                        NullLogger.Instance,
                        CancellationToken.None));

                // THe only features that really turn on are the extra retries (the exception here just ensures the new codepath gets covered)
                // So we'll make sure that the number of tries seen matches the number above.
                Assert.Equal(HttpFileSystemBasedFindPackageByIdResourceTest.SocketExceptionCallsMade, testTryCount);
            }
        }
Пример #3
0
        public async Task HttpFileSystemBasedFindPackageByIdResource_EnhancedHttpRetrySettings()
        {
            const int testTryCount = 7;
            TestEnvironmentVariableReader testEnvironmentVariableReader = new TestEnvironmentVariableReader(
                new Dictionary <string, string>()
            {
                { "NUGET_ENABLE_EXPERIMENTAL_HTTP_RETRY", "true" },
                { "NUGET_EXPERIMENTAL_MAX_NETWORK_TRY_COUNT", $"{testTryCount}" },
                { "NUGET_EXPERIMENTAL_NETWORK_RETRY_DELAY_MILLISECONDS", "0" }
            });

            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync(testEnvironmentVariableReader))
            {
                var exception = await Assert.ThrowsAsync <FatalProtocolException>(
                    () => test.Resource.GetPackageDownloaderAsync(
                        new PackageIdentity(id: "socketexception", version: NuGetVersion.Parse("1.2.3")),
                        test.SourceCacheContext,
                        NullLogger.Instance,
                        CancellationToken.None));

                // THe only features that really turn on are the extra retries (the exception here just ensures the new codepath gets covered)
                // So we'll make sure that the number of tries seen matches the number above.
                Assert.Equal(HttpFileSystemBasedFindPackageByIdResourceTest.SocketExceptionCallsMade, testTryCount);
            }
        }
 public async Task GetPackageDownloaderAsync_ThrowsIfCancelledAsync()
 {
     using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
     {
         await Assert.ThrowsAsync <OperationCanceledException>(
             () => test.Resource.GetPackageDownloaderAsync(
                 new PackageIdentity(id: "a", version: NuGetVersion.Parse("1.0.0")),
                 test.SourceCacheContext,
                 NullLogger.Instance,
                 new CancellationToken(canceled: true)));
     }
 }
 public async Task GetAllVersionsAsync_ThrowIfCancelledAsync()
 {
     using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
     {
         await Assert.ThrowsAsync <OperationCanceledException>(
             () => test.Resource.GetAllVersionsAsync(
                 id: "a",
                 cacheContext: test.SourceCacheContext,
                 logger: NullLogger.Instance,
                 cancellationToken: new CancellationToken(canceled: true)));
     }
 }
        public async Task GetPackageDownloaderAsync_ReturnsNullIfPackageNotFoundAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var downloader = await test.Resource.GetPackageDownloaderAsync(
                    new PackageIdentity(id : "a", version : NuGetVersion.Parse("1.0.0")),
                    test.SourceCacheContext,
                    NullLogger.Instance,
                    CancellationToken.None);

                Assert.Null(downloader);
            }
        }
        public async Task GetPackageDownloaderAsync_ReturnsPackageDownloaderIfPackageFoundAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var downloader = await test.Resource.GetPackageDownloaderAsync(
                    test.PackageIdentity,
                    test.SourceCacheContext,
                    NullLogger.Instance,
                    CancellationToken.None);

                Assert.IsType <RemotePackageArchiveDownloader>(downloader);
            }
        }
        public async Task GetAllVersionsAsync_ReturnsEmptyEnumerableIfPackageIdNotFoundAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var versions = await test.Resource.GetAllVersionsAsync(
                    id : "a",
                    cacheContext : test.SourceCacheContext,
                    logger : NullLogger.Instance,
                    cancellationToken : CancellationToken.None);

                Assert.Empty(versions);
            }
        }
        public async Task GetDependencyInfoAsync_ReturnsNullIfPackageNotFoundAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var dependencyInfo = await test.Resource.GetDependencyInfoAsync(
                    id : "a",
                    version : NuGetVersion.Parse("1.0.0"),
                    cacheContext : test.SourceCacheContext,
                    logger : NullLogger.Instance,
                    cancellationToken : CancellationToken.None);

                Assert.Null(dependencyInfo);
            }
        }
        public async Task GetAllVersionsAsync_ThrowsForNullLoggerAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                    () => test.Resource.GetAllVersionsAsync(
                        id: "a",
                        cacheContext: test.SourceCacheContext,
                        logger: null,
                        cancellationToken: CancellationToken.None));

                Assert.Equal("logger", exception.ParamName);
            }
        }
        public async Task GetAllVersionsAsync_ThrowsForNullOrEmptyIdAsync(string id)
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentException>(
                    () => test.Resource.GetAllVersionsAsync(
                        id,
                        test.SourceCacheContext,
                        NullLogger.Instance,
                        CancellationToken.None));

                Assert.Equal("id", exception.ParamName);
            }
        }
 public async Task CopyNupkgToStreamAsync_ThrowsIfCancelledAsync()
 {
     using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
     {
         await Assert.ThrowsAsync <OperationCanceledException>(
             () => test.Resource.CopyNupkgToStreamAsync(
                 id: "a",
                 version: NuGetVersion.Parse("1.0.0"),
                 destination: Stream.Null,
                 cacheContext: test.SourceCacheContext,
                 logger: NullLogger.Instance,
                 cancellationToken: new CancellationToken(canceled: true)));
     }
 }
        public async Task GetPackageDownloaderAsync_ThrowsForNullSourceCacheContextAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                    () => test.Resource.GetPackageDownloaderAsync(
                        new PackageIdentity(id: "a", version: NuGetVersion.Parse("1.0.0")),
                        cacheContext: null,
                        logger: NullLogger.Instance,
                        cancellationToken: CancellationToken.None));

                Assert.Equal("cacheContext", exception.ParamName);
            }
        }
        public async Task GetPackageDownloaderAsync_ThrowsForNullPackageIdentityAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                    () => test.Resource.GetPackageDownloaderAsync(
                        packageIdentity: null,
                        cacheContext: test.SourceCacheContext,
                        logger: NullLogger.Instance,
                        cancellationToken: CancellationToken.None));

                Assert.Equal("packageIdentity", exception.ParamName);
            }
        }
        public async Task GetDependencyInfoAsync_ThrowsForNullVersionAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                    () => test.Resource.GetDependencyInfoAsync(
                        id: "a",
                        version: null,
                        cacheContext: null,
                        logger: NullLogger.Instance,
                        cancellationToken: CancellationToken.None));

                Assert.Equal("version", exception.ParamName);
            }
        }
        public async Task CopyNupkgToStreamAsync_ThrowsForNullIdAsync(string id)
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentException>(
                    () => test.Resource.CopyNupkgToStreamAsync(
                        id,
                        NuGetVersion.Parse("1.0.0"),
                        Stream.Null,
                        test.SourceCacheContext,
                        NullLogger.Instance,
                        CancellationToken.None));

                Assert.Equal("id", exception.ParamName);
            }
        }
        public async Task CopyNupkgToStreamAsync_ThrowsForNullLoggerAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
            {
                var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                    () => test.Resource.CopyNupkgToStreamAsync(
                        id: "a",
                        version: NuGetVersion.Parse("1.0.0"),
                        destination: Stream.Null,
                        cacheContext: test.SourceCacheContext,
                        logger: null,
                        cancellationToken: CancellationToken.None));

                Assert.Equal("logger", exception.ParamName);
            }
        }
        public async Task CopyNupkgToStreamAsync_ReturnsTrueIfCopiedAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
                using (var stream = new MemoryStream())
                {
                    var wasCopied = await test.Resource.CopyNupkgToStreamAsync(
                        test.PackageIdentity.Id,
                        test.PackageIdentity.Version,
                        stream,
                        test.SourceCacheContext,
                        NullLogger.Instance,
                        CancellationToken.None);

                    Assert.True(wasCopied);
                    Assert.Equal(test.Package.Length, stream.Length);
                }
        }
        public async Task CopyNupkgToStreamAsync_ReturnsFalseIfNotCopiedAsync()
        {
            using (var test = await HttpFileSystemBasedFindPackageByIdResourceTest.CreateAsync())
                using (var stream = new MemoryStream())
                {
                    var wasCopied = await test.Resource.CopyNupkgToStreamAsync(
                        id : "a",
                        version : NuGetVersion.Parse("1.0.0"),
                        destination : stream,
                        cacheContext : test.SourceCacheContext,
                        logger : NullLogger.Instance,
                        cancellationToken : CancellationToken.None);

                    Assert.False(wasCopied);
                    Assert.Equal(0, stream.Length);
                }
        }