コード例 #1
0
        public Task <bool> ProcessPackageDetailsAsync(PackageDetailsCatalogLeaf leaf)
        {
            Console.WriteLine(
                $"{leaf.CommitTimestamp:O}: Found package details leaf for {leaf.PackageId} {leaf.PackageVersion}.");

            return(GetResultAsync(leaf));
        }
コード例 #2
0
ファイル: ModelExtensions.cs プロジェクト: ravinderm/Samples
        /// <summary>
        /// Determines if the provided package details list represents a listed package.
        /// </summary>
        /// <param name="leaf">The catalog leaf.</param>
        /// <returns>True if the package is listed.</returns>
        public static bool IsListed(this PackageDetailsCatalogLeaf leaf)
        {
            if (leaf.Listed.HasValue)
            {
                return(leaf.Listed.Value);
            }

            // A published year of 1900 indicates that this package is unlisted, when the listed property itself is
            // not present (legacy behavior).
            return(leaf.Published.Year == 1900);
        }
コード例 #3
0
            public void PrefersListedProperty(string published, bool listed)
            {
                var leaf = new PackageDetailsCatalogLeaf
                {
                    Published = DateTimeOffset.Parse(published),
                };

                var actual = leaf.IsListed();

                Assert.Equal(listed, actual);
            }
コード例 #4
0
            public void SemVer2PackageVersionMeansSemVer2(string packageVersion, bool isSemVer2)
            {
                var leaf = new PackageDetailsCatalogLeaf
                {
                    PackageVersion  = packageVersion,
                    VerbatimVersion = "1.0.0",
                };

                var actual = leaf.IsSemVer2();

                Assert.Equal(isSemVer2, actual);
            }
コード例 #5
0
            public void AllowsNullDependencyGroups()
            {
                var leaf = new PackageDetailsCatalogLeaf
                {
                    PackageVersion  = "1.0.0",
                    VerbatimVersion = "1.0.0",
                };

                var actual = leaf.IsSemVer2();

                Assert.False(actual);
            }
コード例 #6
0
ファイル: ModelExtensions.cs プロジェクト: nikhgup/NuGet.Jobs
        /// <summary>
        /// Determines if the provided package details leaf represents a listed package.
        /// </summary>
        /// <param name="leaf">The catalog leaf.</param>
        /// <returns>True if the package is listed.</returns>
        public static bool IsListed(this PackageDetailsCatalogLeaf leaf)
        {
            if (leaf.Listed.HasValue)
            {
                return(leaf.Listed.Value);
            }

            // A published year of 1900 indicates that this package is unlisted, when the listed property itself is
            // not present (legacy behavior).
            // Example: https://api.nuget.org/v3/catalog0/data/2015.02.01.06.22.45/antixss.4.0.1.json
            return(leaf.Published.Year != 1900);
        }
コード例 #7
0
ファイル: ModelExtensions.cs プロジェクト: nikhgup/NuGet.Jobs
        /// <summary>
        /// Determines if the provied package details leaf represents a SemVer 2.0.0 package. A package is considered
        /// SemVer 2.0.0 if it's version is SemVer 2.0.0 or one of its dependency version ranges is SemVer 2.0.0.
        /// </summary>
        /// <param name="leaf">The catalog leaf.</param>
        /// <returns>True if the package is SemVer 2.0.0.</returns>
        public static bool IsSemVer2(this PackageDetailsCatalogLeaf leaf)
        {
            var parsedPackageVersion = leaf.ParsePackageVersion();

            if (parsedPackageVersion.IsSemVer2)
            {
                return(true);
            }

            if (leaf.VerbatimVersion != null)
            {
                var parsedVerbatimVersion = NuGetVersion.Parse(leaf.VerbatimVersion);
                if (parsedVerbatimVersion.IsSemVer2)
                {
                    return(true);
                }
            }

            if (leaf.DependencyGroups != null)
            {
                foreach (var dependencyGroup in leaf.DependencyGroups)
                {
                    // Example: https://api.nuget.org/v3/catalog0/data/2018.10.28.07.42.42/mvcsitemapprovider.3.3.0-pre1.json
                    if (dependencyGroup.Dependencies == null)
                    {
                        continue;
                    }

                    foreach (var dependency in dependencyGroup.Dependencies)
                    {
                        var versionRange = dependency.ParseRange();
                        if ((versionRange.MaxVersion != null && versionRange.MaxVersion.IsSemVer2) ||
                            (versionRange.MinVersion != null && versionRange.MinVersion.IsSemVer2))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #8
0
            public void SemVer2DependencyVersionRangeMeansSemVer2(string range, bool isSemVer2)
            {
                var leaf = new PackageDetailsCatalogLeaf
                {
                    PackageVersion   = "1.0.0",
                    VerbatimVersion  = "1.0.0",
                    DependencyGroups = new List <PackageDependencyGroup>
                    {
                        new PackageDependencyGroup
                        {
                            Dependencies = new List <PackageDependency>
                            {
                                new PackageDependency
                                {
                                    Range = "0.0.0",
                                },
                            },
                        },
                        new PackageDependencyGroup
                        {
                            Dependencies = new List <PackageDependency>
                            {
                                new PackageDependency
                                {
                                    Range = "0.0.1",
                                },
                                new PackageDependency
                                {
                                    Range = range,
                                },
                            },
                        },
                    },
                };

                var actual = leaf.IsSemVer2();

                Assert.Equal(isSemVer2, actual);
            }
コード例 #9
0
            public void AllowsNullVerbatimVersion()
            {
                var leaf = new PackageDetailsCatalogLeaf
                {
                    PackageVersion   = "1.0.0",
                    DependencyGroups = new List <PackageDependencyGroup>
                    {
                        new PackageDependencyGroup
                        {
                            Dependencies = new List <PackageDependency>
                            {
                                new PackageDependency
                                {
                                    Range = "[1.0.0, )",
                                },
                            },
                        },
                    },
                };

                var actual = leaf.IsSemVer2();

                Assert.False(actual);
            }