Exemple #1
0
        public async Task PackageSearchResourceV3_UsesReferenceCache()
        {
            // Arrange
            var responses = new Dictionary <string, string>();

            responses.Add("https://api-v3search-0.nuget.org/query?q=entityframework&skip=0&take=2&prerelease=false&semVerLevel=2.0.0",
                          ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.SearchV3WithDuplicateBesidesVersion.json", GetType()));
            responses.Add("http://testsource.com/v3/index.json", JsonData.IndexWithoutFlatContainer);

            var repo = StaticHttpHandler.CreateSource("http://testsource.com/v3/index.json", Repository.Provider.GetCoreV3(), responses);

            var resource = await repo.GetResourceAsync <PackageSearchResource>();

            // Act
            var packages = (IEnumerable <PackageSearchMetadataBuilder.ClonedPackageSearchMetadata>) await resource.SearchAsync(
                "entityframework",
                new SearchFilter(false),
                skip : 0,
                take : 2,
                log : NullLogger.Instance,
                cancellationToken : CancellationToken.None);

            var first  = packages.ElementAt(0);
            var second = packages.ElementAt(1);

            // Assert
            MetadataReferenceCacheTestUtility.AssertPackagesHaveSameReferences(first, second);
        }
        public async Task TestUsesReferenceCache()
        {
            // Arrange
            var serviceAddress = TestUtility.CreateServiceAddress() + "api/v2";

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

            responses.Add(
                serviceAddress + "/Search()?$orderby=Id&searchTerm='afine'" +
                "&targetFramework=''&includePrerelease=false&$skip=0&$top=30&semVerLevel=2.0.0",
                TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.SearchV2WithDuplicateBesidesVersion.xml", GetType()));
            responses.Add(serviceAddress, string.Empty);
            responses.Add(serviceAddress + "/$metadata",
                          TestUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.MetadataTT.xml", GetType()));

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

            var parser         = new V2FeedParser(httpSource, serviceAddress);
            var legacyResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceAddress);
            var resource       = new V2FeedListResource(parser, legacyResource, serviceAddress);

            var enumerable = await resource.ListAsync(searchTerm : "afine",
                                                      prerelease : false, allVersions : true, includeDelisted : true, logger : NullLogger.Instance, token : CancellationToken.None);

            int ExpectedCount = 2;
            int ActualCount   = 0;
            var enumerator    = enumerable.GetEnumeratorAsync();

            var packages = new List <PackageSearchMetadataBuilder.ClonedPackageSearchMetadata>();

            while (await enumerator.MoveNextAsync())
            {
                if (enumerator.Current != null)
                {
                    ActualCount++;
                    Assert.True(ExpectedCount >= ActualCount, "Too many results");
                    packages.Add((PackageSearchMetadataBuilder.ClonedPackageSearchMetadata)enumerator.Current);
                }
                else
                {
                    Assert.False(false, "Null Value, this shouldn't happen.");
                }
            }

            Assert.Equal(ExpectedCount, ActualCount);

            MetadataReferenceCacheTestUtility.AssertPackagesHaveSameReferences(packages[0], packages[1]);
        }
Exemple #3
0
        public async Task PackageMetadataResourceV3_UsesReferenceCache()
        {
            // Arrange
            var responses = new Dictionary <string, string>();

            responses.Add("http://testsource.com/v3/index.json", JsonData.IndexWithoutFlatContainer);
            responses.Add("https://api.nuget.org/v3/registration0/afine/index.json", JsonData.DuplicatePackageBesidesVersionRegistrationIndex);

            var repo = StaticHttpHandler.CreateSource("http://testsource.com/v3/index.json", Repository.Provider.GetCoreV3(), responses);

            var resource = await repo.GetResourceAsync <PackageMetadataResource>();

            // Act
            var result = (IEnumerable <PackageSearchMetadataRegistration>) await resource.GetMetadataAsync("afine", true, true, Common.NullLogger.Instance, CancellationToken.None);

            var first  = result.ElementAt(0);
            var second = result.ElementAt(1);

            // Assert
            MetadataReferenceCacheTestUtility.AssertPackagesHaveSameReferences(first, second);
        }
        public async Task PackageMetadataResource_UsesReferenceCache()
        {
            // Arrange
            var serviceAddress = ProtocolUtility.CreateServiceAddress();

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

            responses.Add(serviceAddress + "FindPackagesById()?id='afine'&semVerLevel=2.0.0",
                          ProtocolUtility.GetResource("NuGet.Protocol.Tests.compiler.resources.FindPackagesByIdWithDuplicateBesidesVersion.xml", GetType()));
            responses.Add(serviceAddress, string.Empty);

            var repo = StaticHttpHandler.CreateSource(serviceAddress, Repository.Provider.GetCoreV3(), responses);

            var packageMetadataResource = await repo.GetResourceAsync <PackageMetadataResource>();

            // Act
            var metadata = await packageMetadataResource.GetMetadataAsync("afine", true, false, NullSourceCacheContext.Instance, NullLogger.Instance, CancellationToken.None);

            var first  = metadata.ElementAt(0);
            var second = metadata.ElementAt(1);

            // Assert
            MetadataReferenceCacheTestUtility.AssertPackagesHaveSameReferences(first, second);
        }