Ejemplo n.º 1
0
        public LocalPackageInfo FindPackage(string packageId, NuGetVersion version)
        {
            LocalPackageInfo package = null;

            var packages = FindPackagesByIdImpl(packageId);
            var count    = packages.Count;

            for (var i = 0; i < count; i++)
            {
                var candidatePackage = packages[i];
                if (candidatePackage.Version == version)
                {
                    package = candidatePackage;
                    break;
                }
            }

            if (package == null)
            {
                return(null);
            }

            // Check for an exact match on casing
            if (StringComparer.Ordinal.Equals(packageId, package.Id) &&
                EqualityUtility.SequenceEqualWithNullCheck(version.ReleaseLabels, package.Version.ReleaseLabels, StringComparer.Ordinal))
            {
                return(package);
            }

            // nuspec
            var nuspec = _nuspecCache.GetOrAdd(package.ManifestPath, package.ExpandedPath);

            // Create a new info to match the given id/version
            return(new LocalPackageInfo(
                       packageId,
                       version,
                       package.ExpandedPath,
                       package.ManifestPath,
                       package.ZipPath,
                       nuspec));
        }
Ejemplo n.º 2
0
        public async Task LocalNuspecCache_GetNuspecTwiceVerifySameInstance()
        {
            using (var pathContext = new SimpleTestPathContext())
            {
                var cache        = new LocalNuspecCache();
                var pathResolver = new VersionFolderPathResolver(pathContext.PackageSource);

                var identity = new PackageIdentity("X", NuGetVersion.Parse("1.0.0"));

                await SimpleTestPackageUtility.CreateFolderFeedV3(
                    pathContext.PackageSource,
                    identity);

                var nuspec   = pathResolver.GetManifestFilePath(identity.Id, identity.Version);
                var expanded = pathResolver.GetInstallPath(identity.Id, identity.Version);

                var result1 = cache.GetOrAdd(nuspec, expanded);
                var result2 = cache.GetOrAdd(nuspec, expanded);

                Assert.Same(result1.Value, result2.Value);
                result1.Value.GetIdentity().Should().Be(identity);
            }
        }
Ejemplo n.º 3
0
        public void LocalNuspecCache_DirNotFoundVerifyFailure()
        {
            using (var pathContext = new SimpleTestPathContext())
            {
                var cache        = new LocalNuspecCache();
                var pathResolver = new VersionFolderPathResolver(pathContext.PackageSource);

                var identity = new PackageIdentity("X", NuGetVersion.Parse("1.0.0"));

                var nuspec   = pathResolver.GetManifestFilePath(identity.Id, identity.Version);
                var expanded = pathResolver.GetInstallPath(identity.Id, identity.Version);

                // Verify does not throw
                var result = cache.GetOrAdd(nuspec, expanded);

                // This should throw
                Assert.Throws <DirectoryNotFoundException>(() => result.Value);
            }
        }
Ejemplo n.º 4
0
        public async Task LocalNuspecCache_FallbackToFolderReaderVerifyResult()
        {
            using (var pathContext = new SimpleTestPathContext())
            {
                var cache        = new LocalNuspecCache();
                var pathResolver = new VersionFolderPathResolver(pathContext.PackageSource);

                var identity = new PackageIdentity("X", NuGetVersion.Parse("1.0.0"));

                await SimpleTestPackageUtility.CreateFolderFeedV3(
                    pathContext.PackageSource,
                    identity);

                var nuspec   = pathResolver.GetManifestFilePath(identity.Id, identity.Version) + "invalid.nuspec";
                var expanded = pathResolver.GetInstallPath(identity.Id, identity.Version);

                var result = cache.GetOrAdd(nuspec, expanded);

                result.Value.GetIdentity().Should().Be(identity);
            }
        }