Example #1
0
        public async Task TestDownloadAsyncWithProgressAsync_Unknown_File_Size()
        {
            var packageSource      = new NugetOrgOfficialV2PackageSources().Items.Single();
            var percentages        = new List <int>();
            var progressSourceMock = new Mock <INugetServiceProgressSource>();

            progressSourceMock
            .Setup(x => x.Raise(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <long>(), It.IsAny <long>()))
            .Callback((int percentage, long bytesRead, long totalBytesDownloadedSoFar, long totalBytesToDownload) =>
            {
                percentages.Add(percentage);
            });

            var downloadContext = new DownloadContext
            {
                PackageIdentity = new PackageIdentity("LibLog", NuGetVersion.Parse("5.0.6")),
                PackageFileSize = 0,
                MaxTries        = 3
            };

            using (var downloadResourceResult = await _nugetService.DownloadAsyncWithProgressAsync(packageSource, downloadContext,
                                                                                                   progressSourceMock.Object, CancellationToken.None))
            {
                const long expectedPackageSize = 64196;

                Assert.NotNull(downloadResourceResult);
                Assert.Equal(expectedPackageSize, downloadResourceResult.PackageStream.Length);
                Assert.Equal(0, downloadResourceResult.PackageStream.Position);

                progressSourceMock.Verify(x => x.Raise(
                                              It.Is <int>(v => v == 0),
                                              It.Is <long>(v => v == 0),
                                              It.Is <long>(v => v == 0),
                                              It.Is <long>(v => v == 0)), Times.Once);

                progressSourceMock.Verify(x => x.Raise(
                                              It.Is <int>(v => v == 50),
                                              It.IsAny <long>(),
                                              It.IsAny <long>(),
                                              It.Is <long>(v => v == 0)), Times.AtLeastOnce);

                progressSourceMock.Verify(x => x.Raise(
                                              It.Is <int>(v => v == 100),
                                              It.IsAny <long>(),
                                              It.Is <long>(v => v == expectedPackageSize),
                                              It.Is <long>(v => v == 0)), Times.Once);
            }

            Assert.Equal(progressSourceMock.Invocations.Count, percentages.Count);
        }
Example #2
0
        public async Task TestGetMetadatasAsync()
        {
            var packageSources = new NugetOrgOfficialV2PackageSources();

            var packages = await _nugetService
                           .GetMetadatasAsync("Nuget.Packaging", packageSources, CancellationToken.None, false);

            Assert.NotEmpty(packages);

            var v450Release = packages.SingleOrDefault(x => x.Identity.Version == SemanticVersion.Parse("4.5.0"));
            var v492Release = packages.SingleOrDefault(x => x.Identity.Version == SemanticVersion.Parse("4.9.2"));

            Assert.NotNull(v450Release);
            Assert.NotNull(v492Release);
        }
Example #3
0
        public void TestNugetOrgPackageSourcesV2()
        {
            var packageSources = new NugetOrgOfficialV2PackageSources();

            Assert.Single(packageSources.Items);

            var packageSource = packageSources.Items.Single();

            Assert.Equal(1, packageSource.ProtocolVersion);
            Assert.Equal(NuGetConstants.V2FeedUrl, packageSource.Source);
            Assert.True(packageSource.IsEnabled);
            Assert.True(packageSource.IsMachineWide);
            Assert.False(packageSource.IsPersistable);
            Assert.Equal("nuget.org", packageSource.Name);
        }
Example #4
0
        public async Task TestBuildV2FeedParser()
        {
            var nugetOrgOfficialV3PackageSources = new NugetOrgOfficialV2PackageSources();

            var nugetOrgPackageSourceV2 = nugetOrgOfficialV3PackageSources.Items.Single();

            Assert.True(nugetOrgPackageSourceV2.Source == NuGetConstants.V2FeedUrl);

            var sourceRepository   = new SourceRepository(nugetOrgPackageSourceV2, Repository.Provider.GetCoreV3());
            var downloadResourceV3 = (DownloadResourceV2Feed)await sourceRepository.GetResourceAsync <DownloadResource>();

            Assert.NotNull(downloadResourceV3);

            var httpSource = downloadResourceV3.BuildV2FeedParser();

            Assert.NotNull(httpSource);
            Assert.Equal("https://www.nuget.org/api/v2/", httpSource.Source);
        }