public async Task ResolvesVersion_Correctly(string current, VersionLock versionLock, PrereleaseReporting prerelease, string latest)
        {
            // Arrange

            // Act
            var latestVersion = await _nuGetPackageResolutionService.ResolvePackageVersions(packageName, NuGetVersion.Parse(current), new List <Uri>(), VersionRange.Parse(current), versionLock, prerelease, null, null, false);

            // Assert
            Assert.Equal(NuGetVersion.Parse(latest), latestVersion);
        }
コード例 #2
0
        public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, IEnumerable <Uri> sources, VersionRange currentVersionRange,
                                                                VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath, bool isDevelopmentDependency, int olderThanDays, bool ignoreFailedSources = false)
        {
            // Determine whether we are interested in pre-releases
            bool includePrerelease = referencedVersion.IsPrerelease;

            if (prerelease == PrereleaseReporting.Always)
            {
                includePrerelease = true;
            }
            else if (prerelease == PrereleaseReporting.Never)
            {
                includePrerelease = false;
            }

            string cacheKey = (packageName + "-" + includePrerelease + "-" + targetFrameworkName + "-" + olderThanDays).ToLowerInvariant();

            // Get all the available versions
            var allVersionsRequest = new Lazy <Task <IReadOnlyList <NuGetVersion> > >(() => this._nugetService.GetAllVersions(packageName, sources, includePrerelease, targetFrameworkName, projectFilePath, isDevelopmentDependency, olderThanDays, ignoreFailedSources));
            var allVersions        = await this._cache.GetOrAdd(cacheKey, allVersionsRequest).Value;

            // Determine the floating behaviour
            var floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.AbsoluteLatest : NuGetVersionFloatBehavior.Major;

            if (versionLock == VersionLock.Major)
            {
                floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.PrereleaseMinor : NuGetVersionFloatBehavior.Minor;
            }
            if (versionLock == VersionLock.Minor)
            {
                floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.PrereleasePatch : NuGetVersionFloatBehavior.Patch;
            }

            string releasePrefix = null;

            if (referencedVersion.IsPrerelease)
            {
                releasePrefix = referencedVersion.ReleaseLabels.First(); // TODO Not sure exactly what to do for this bit
            }
            // Create a new version range for comparison
            var latestVersionRange = new VersionRange(currentVersionRange, new FloatRange(floatingBehaviour, referencedVersion, releasePrefix));

            // Use new version range to determine latest version
            NuGetVersion latestVersion = latestVersionRange.FindBestMatch(allVersions);

            return(latestVersion);
        }
コード例 #3
0
        public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, IEnumerable <Uri> sources, VersionRange currentVersionRange,
                                                                VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath, bool isDevelopmentDependency)
        {
            // Determine whether we are interested in pre-releases
            bool includePrerelease = referencedVersion.IsPrerelease;

            if (prerelease == PrereleaseReporting.Always)
            {
                includePrerelease = true;
            }
            else if (prerelease == PrereleaseReporting.Never)
            {
                includePrerelease = false;
            }

            string cacheKey = (packageName + "-" + includePrerelease + "-" + targetFrameworkName).ToLowerInvariant();

            if (!_cache.TryGetValue(cacheKey, out var allVersions))
            {
                // Get all the available versions
                allVersions = await _nugetService.GetAllVersions(packageName, sources, includePrerelease, targetFrameworkName, projectFilePath, isDevelopmentDependency);

                _cache.Add(cacheKey, allVersions);
            }

            // Determine the floating behaviour
            var floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.AbsoluteLatest : NuGetVersionFloatBehavior.Major;

            if (versionLock == VersionLock.Major)
            {
                floatingBehaviour = NuGetVersionFloatBehavior.Minor;
            }
            if (versionLock == VersionLock.Minor)
            {
                floatingBehaviour = NuGetVersionFloatBehavior.Patch;
            }

            // Create a new version range for comparison
            var latestVersionRange = new VersionRange(currentVersionRange, new FloatRange(floatingBehaviour, referencedVersion));

            // Use new version range to determine latest version
            NuGetVersion latestVersion = latestVersionRange.FindBestMatch(allVersions);

            return(latestVersion);
        }
コード例 #4
0
        public async Task <(NuGetVersion referencedVersion, NuGetVersion latestVersion)> ResolvePackageVersions(
            string package, List <Uri> sources, VersionRange currentVersionRange, VersionLock versionLock, PrereleaseReporting prerelease)
        {
            // Get all the available versions
            var allVersions = await _nugetService.GetAllVersions(package, sources);

            // Resolve the referenced versions
            NuGetVersion referencedVersion = currentVersionRange.FindBestMatch(allVersions);

            // Determine whether we are interested in pre-releases
            bool includePrerelease = referencedVersion.IsPrerelease;

            if (prerelease == PrereleaseReporting.Always)
            {
                includePrerelease = true;
            }
            else if (prerelease == PrereleaseReporting.Never)
            {
                includePrerelease = false;
            }

            // Determine the floating behaviour
            var floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.AbsoluteLatest : NuGetVersionFloatBehavior.Major;

            if (versionLock == VersionLock.Major)
            {
                floatingBehaviour = NuGetVersionFloatBehavior.Minor;
            }
            if (versionLock == VersionLock.Minor)
            {
                floatingBehaviour = NuGetVersionFloatBehavior.Patch;
            }

            // Create a new version range for comparison
            var latestVersionRange = new VersionRange(currentVersionRange, new FloatRange(floatingBehaviour, referencedVersion));

            // Use new version range to determine latest version
            NuGetVersion latestVersion = latestVersionRange.FindBestMatch(allVersions);

            return(referencedVersion, latestVersion);
        }
コード例 #5
0
 public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, IEnumerable <Uri> sources, VersionRange currentVersionRange,
                                                         VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath, bool isDevelopmentDependency)
 {
     return(await ResolvePackageVersions(packageName, referencedVersion, sources, currentVersionRange, versionLock, prerelease, targetFrameworkName, projectFilePath,
                                         isDevelopmentDependency, 0));
 }