Ejemplo n.º 1
0
        public async Task <IEnumerable <IPackageSearchMetadata> > GetSearchPageForIdAsync(Uri searchBaseUri)
        {
            var lazyTask = _searchPageForIdCache.GetOrAdd(
                searchBaseUri,
                _ => new Lazy <Task <IEnumerable <IPackageSearchMetadata> > >(() =>
            {
                var queryUri = new Uri(searchBaseUri, "/query");
                _logger.LogInformation(
                    "Searching for package {Id} on {Uri}.",
                    Package.Id,
                    queryUri.AbsoluteUri);

                var rawSearchResource     = new RawSearchResourceV3(_httpSourceResource.HttpSource, new[] { queryUri });
                var packageSearchResource = new PackageSearchResourceV3(rawSearchResource);
                return(packageSearchResource.SearchAsync(
                           searchTerm: $"packageid:{Package.Id}",
                           filter: new SearchFilter(includePrerelease: true),
                           skip: 0,
                           take: 1,
                           log: _commonLogger,
                           cancellationToken: CancellationToken));
            }));

            return(await lazyTask.Value);
        }
Ejemplo n.º 2
0
        private PackageSearchResourceV3 GetSearch()
        {
            RawSearchResourceV3 rawSearchResource = _sourceRepository.GetResource <RawSearchResourceV3>();

            Assert.NotNull(rawSearchResource);
            var search = new PackageSearchResourceV3(rawSearchResource);

            return(search);
        }
Ejemplo n.º 3
0
        private PackageSearchResourceV3 GetSearch()
        {
            PackageMetadataResourceV3 packageMetadataRes = GetPackageMetadataResource();
            RawSearchResourceV3       rawSearchResource  = _sourceRepository.GetResource <RawSearchResourceV3>();

            Assert.NotNull(rawSearchResource);
            var search = new PackageSearchResourceV3(rawSearchResource, packageMetadataRes);

            return(search);
        }
Ejemplo n.º 4
0
        [Trait("Category", "integration")] // because it uses external nupkg files
        public async Task PushOneThenSearchPackage()
        {
            InitializeClient(MainIndex);
            var packageResource = await _sourceRepository.GetResourceAsync <PackageUpdateResource>();

            await packageResource.Push(TestResources.GetNupkgBagetTest1(),
                                       null, 5, false, GetApiKey, GetApiKey, false, logger);

            PackageSearchResourceV3 search = GetSearch();
            var found = await search.SearchAsync("liget-test1", new SearchFilter(true), 0, 10, logger, CancellationToken.None);

            Assert.NotEmpty(found);
            var one = found.First();

            Assert.Equal(new PackageIdentity("liget-test1", NuGetVersion.Parse("1.0.0")), one.Identity);
        }
Ejemplo n.º 5
0
        public async Task PackageSearchResourceV3_VerifyReadSyncIsNotUsed()
        {
            // Arrange
            var serviceAddress = ProtocolUtility.CreateServiceAddress();

            var responses = new Dictionary <string, string>();

            responses.Add(
                serviceAddress + "?q=azure%20b&skip=0&take=1&prerelease=false" +
                "&supportedFramework=.NETFramework,Version=v4.5&semVerLevel=2.0.0",
                ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.V3Search.json", GetType()));
            responses.Add(serviceAddress, string.Empty);

            var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses);

            // throw if sync .Read is used
            httpSource.StreamWrapper = (stream) => new NoSyncReadStream(stream);

            var packageSearchResourceV3 = new PackageSearchResourceV3(httpSource, new Uri[] { new Uri(serviceAddress) });

            var searchFilter = new SearchFilter(includePrerelease: false)
            {
                SupportedFrameworks = new string[] { ".NETFramework,Version=v4.5" }
            };
            var skip = 0;
            var take = 1;

            // Act
            var packages = await packageSearchResourceV3.Search(
                "azure b",
                searchFilter,
                skip,
                take,
                NullLogger.Instance,
                CancellationToken.None);

            var packagesArray = packages.ToArray();

            // Assert
            // Verify that the url matches the one in the response dictionary
            // Verify no failures from Sync Read
            Assert.True(packagesArray.Length > 0);
        }
Ejemplo n.º 6
0
        public async Task PackageSearchResourceV3_CancelledToken_ThrowsOperationCancelledException()
        {
            // Arrange
            var serviceAddress = ProtocolUtility.CreateServiceAddress();

            var responses = new Dictionary <string, string>();

            responses.Add(
                serviceAddress + "?q=azure%20b&skip=0&take=1&prerelease=false" +
                "&supportedFramework=.NETFramework,Version=v4.5&semVerLevel=2.0.0",
                ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.V3Search.json", GetType()));
            responses.Add(serviceAddress, string.Empty);

            var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses);

            httpSource.StreamWrapper = (stream) => new NoSyncReadStream(stream);

            var packageSearchResourceV3 = new PackageSearchResourceV3(httpSource, new Uri[] { new Uri(serviceAddress) });

            var searchFilter = new SearchFilter(includePrerelease: false)
            {
                SupportedFrameworks = new string[] { ".NETFramework,Version=v4.5" }
            };

            var tokenSource = new CancellationTokenSource();

            tokenSource.Cancel();
            var skip = 0;
            var take = 1;

            // Act/Assert
            await Assert.ThrowsAsync <TaskCanceledException>(() =>
                                                             packageSearchResourceV3.Search(
                                                                 "Sentry",
                                                                 searchFilter,
                                                                 skip,
                                                                 take,
                                                                 NullLogger.Instance,
                                                                 tokenSource.Token));
        }
Ejemplo n.º 7
0
        [Trait("Category", "integration")] // because it uses external nupkg files
        public async Task Push2VersionsThenSearchPackage()
        {
            InitializeClient(MainIndex);
            var packageResource = await _sourceRepository.GetResourceAsync <PackageUpdateResource>();

            await packageResource.Push(TestResources.GetNupkgBagetTwoV1(),
                                       null, 5, false, GetApiKey, GetApiKey, false, logger);

            await packageResource.Push(TestResources.GetNupkgBagetTwoV2(),
                                       null, 5, false, GetApiKey, GetApiKey, false, logger);

            PackageSearchResourceV3 search = GetSearch();
            var found = await search.SearchAsync("liget-two", new SearchFilter(true), 0, 10, logger, CancellationToken.None);

            Assert.NotEmpty(found);
            var ids = found.Select(p => p.Identity);

            Assert.Contains(ids, p => p.Version.Equals(NuGetVersion.Parse("2.1.0")));
            var versions = await found.First().GetVersionsAsync();

            Assert.Contains(versions, p => p.Version.Equals(NuGetVersion.Parse("1.0.0")));
            Assert.Contains(versions, p => p.Version.Equals(NuGetVersion.Parse("2.1.0")));
        }