From d503079c71fe9aaf369ce09398123be27219ac30 Mon Sep 17 00:00:00 2001 From: pymenguy <167523107+pymenguy@users.noreply.github.com> Date: Mon, 3 Feb 2025 07:36:40 +0100 Subject: [PATCH] Add/license url override (#102) --- .../PackageInformationReader/CustomPackageInformation.cs | 2 +- src/NuGetUtility/PackageInformationReader/PackageMetadata.cs | 2 +- .../PackageInformationReader/PackageInformationReaderTest.cs | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs b/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs index e19a45b5..7e76612d 100644 --- a/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs +++ b/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs @@ -5,5 +5,5 @@ namespace NuGetUtility.PackageInformationReader { - public record struct CustomPackageInformation(string Id, INuGetVersion Version, string License, string? Copyright = null, string? Authors = null, string? Title = null, string? ProjectUrl = null, string? Summary = null, string? Description = null); + public record struct CustomPackageInformation(string Id, INuGetVersion Version, string License, Uri? LicenseUrl = null, string? Copyright = null, string? Authors = null, string? Title = null, string? ProjectUrl = null, string? Summary = null, string? Description = null); } diff --git a/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs b/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs index ca4e3f93..28090cd0 100644 --- a/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs +++ b/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs @@ -26,7 +26,7 @@ public PackageMetadata(PackageIdentity identity, LicenseType licenseType, Custom public string? Title => CustomPackageInformation?.Title; - public Uri? LicenseUrl => null; + public Uri? LicenseUrl => CustomPackageInformation?.LicenseUrl; public string? ProjectUrl => CustomPackageInformation?.ProjectUrl; diff --git a/tests/NuGetUtility.Test/PackageInformationReader/PackageInformationReaderTest.cs b/tests/NuGetUtility.Test/PackageInformationReader/PackageInformationReaderTest.cs index 47c51846..0d21a0e5 100644 --- a/tests/NuGetUtility.Test/PackageInformationReader/PackageInformationReaderTest.cs +++ b/tests/NuGetUtility.Test/PackageInformationReader/PackageInformationReaderTest.cs @@ -95,6 +95,7 @@ private static void CheckResult(ReferencedPackageWithContext[] result, Assert.That(packages, Is.EquivalentTo(result.Select(s => new CustomPackageInformation(s.PackageInfo.Identity.Id, s.PackageInfo.Identity.Version, s.PackageInfo.LicenseMetadata!.License, + s.PackageInfo.LicenseUrl, s.PackageInfo.Copyright, s.PackageInfo.Authors, s.PackageInfo.Title, @@ -125,6 +126,7 @@ public async Task GetPackageInfo_Should_PreferLocalPackageCacheOverRepositories( mockedInfo.Summary.Returns(info.Summary); mockedInfo.Description.Returns(info.Description); mockedInfo.LicenseMetadata.Returns(new LicenseMetadata(LicenseType.Expression, info.License)); + mockedInfo.LicenseUrl.Returns(info.LicenseUrl); _globalPackagesFolderUtility.GetPackage(identity).Returns(mockedInfo); return identity; @@ -147,6 +149,7 @@ private static void SetupPackagesForRepositories(IEnumerable(); resultingInfo.Identity.Returns(new PackageIdentity(package.Id, package.Version)); resultingInfo.LicenseMetadata.Returns(new LicenseMetadata(LicenseType.Expression, package.License)); + resultingInfo.LicenseUrl.Returns(package.LicenseUrl); resultingInfo.Copyright.Returns(package.Copyright); resultingInfo.Authors.Returns(package.Authors); resultingInfo.Title.Returns(package.Title);