Exemple #1
0
        public async Task TestGetMetadataByPackageIdentity()
        {
            var stablePackageIdentity     = new PackageIdentity("LibLog", NuGetVersion.Parse("5.0.5"));
            var preReleasePackageIdentity = new PackageIdentity("LibLog", NuGetVersion.Parse("5.0.7-build.575"));
            var packageSource             = new NugetOrgOfficialV3PackageSources().Items.Single();

            var stableMetadata = await _nugetService.GetMetadataByPackageIdentity(stablePackageIdentity, packageSource, null, default, true);
Exemple #2
0
        public async Task TestGetMetadatasAsync_Include_PreRelease()
        {
            var packageSources = new NugetOrgOfficialV3PackageSources();

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

            Assert.NotEmpty(packages.Where(x => x.Identity.Version.IsPrerelease));
            Assert.NotEmpty(packages.Where(x => !x.Identity.Version.IsPrerelease));
        }
Exemple #3
0
        public void TestIsProtocolV3()
        {
            var packageSources = new NugetOrgOfficialV3PackageSources();

            Assert.Single(packageSources.Items);

            var packageSource = packageSources.Items.Single();

            Assert.True(packageSource.Source == NuGetConstants.V3FeedUrl);
        }
        public async Task TestDirectDownloadWithProgressAsync_Unknown_File_Size()
        {
            var packageSource      = new NugetOrgOfficialV3PackageSources().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 totalBytesSoFar, long totalBytesDownloaded) =>
            {
                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);
        }
Exemple #5
0
        public async Task TestSearchAsync()
        {
            var packageSources = new NugetOrgOfficialV3PackageSources();

            var packages = (await _nugetService
                            .SearchAsync("Nuget.Packaging", new SearchFilter(false), 0, 30, packageSources, CancellationToken.None)).ToList();

            Assert.NotEmpty(packages);

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

            Assert.Null(v450Release);
        }
Exemple #6
0
        public async Task TestDownloadAsync()
        {
            var packageIdentity = new PackageIdentity("LibLog", NuGetVersion.Parse("5.0.5"));
            var packageSource   = new NugetOrgOfficialV3PackageSources().Items.Single();

            using var downloadResourceResult = await _nugetService.DownloadAsync(packageSource, packageIdentity, CancellationToken.None);

            Assert.Equal(DownloadResourceResultStatus.Available, downloadResourceResult.Status);

            Assert.True(downloadResourceResult.PackageStream.CanRead);
            Assert.Equal(63411, downloadResourceResult.PackageStream.Length);

            Assert.Null(downloadResourceResult.PackageReader);
        }
Exemple #7
0
        public async Task TestGetMetadatasAsync()
        {
            var packageSources = new NugetOrgOfficialV3PackageSources();

            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(v492Release);
            Assert.NotNull(v450Release);
        }
Exemple #8
0
        public void TestNugetOrgPackageSourcesV3()
        {
            var source = new NugetOrgOfficialV3PackageSources();

            Assert.Single(source.Items);

            var item = source.Items.Single();

            Assert.Equal(2, item.ProtocolVersion);
            Assert.Equal(NuGetConstants.V3FeedUrl, item.Source);
            Assert.True(item.IsEnabled);
            Assert.True(item.IsMachineWide);
            Assert.False(item.IsPersistable);
            Assert.Equal("nuget.org", item.Name);
        }
        public async Task TestBuildHttpSource()
        {
            var nugetOrgOfficialV3PackageSources = new NugetOrgOfficialV3PackageSources();

            var nugetOrgPackageSourceV3 = nugetOrgOfficialV3PackageSources.Items.Single();

            Assert.True(nugetOrgPackageSourceV3.Source == NuGetConstants.V3FeedUrl);

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

            Assert.NotNull(downloadResourceV3);

            var httpSource = downloadResourceV3.BuildHttpSource();

            Assert.NotNull(httpSource);
            Assert.Equal("https://api.nuget.org/v3/index.json", httpSource.PackageSource);
        }