From c92f51c5252fcba6daaa7417147b1be4e4d10637 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Fri, 10 Oct 2025 15:20:11 -0700 Subject: [PATCH 1/3] Support ExactVersion --- .../{Update/Package.cs => NuGetPackage.cs} | 61 +++-- .../Package/Update/PackageUpdateArgs.cs | 2 +- .../Package/Update/PackageUpdateCommand.cs | 6 +- .../Update/PackageUpdateCommandRunner.cs | 10 +- .../NuGet.CommandLine.XPlat/Messages.cs | 6 + .../Strings.Designer.cs | 11 +- .../NuGet.CommandLine.XPlat/Strings.resx | 4 + .../xlf/Strings.cs.xlf | 5 + .../xlf/Strings.de.xlf | 5 + .../xlf/Strings.es.xlf | 5 + .../xlf/Strings.fr.xlf | 5 + .../xlf/Strings.it.xlf | 5 + .../xlf/Strings.ja.xlf | 5 + .../xlf/Strings.ko.xlf | 5 + .../xlf/Strings.pl.xlf | 5 + .../xlf/Strings.pt-BR.xlf | 5 + .../xlf/Strings.ru.xlf | 5 + .../xlf/Strings.tr.xlf | 5 + .../xlf/Strings.zh-Hans.xlf | 5 + .../xlf/Strings.zh-Hant.xlf | 5 + .../Commands/Package/NuGetPackageTests.cs | 217 ++++++++++++++++++ .../Commands/Package/Update/PackageTests.cs | 122 ---------- .../GetPackageToUpdateTests.cs | 2 +- .../MultiProjectTests.cs | 2 +- .../SingleProjectTests.cs | 2 +- 25 files changed, 360 insertions(+), 150 deletions(-) rename src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/{Update/Package.cs => NuGetPackage.cs} (50%) create mode 100644 test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs delete mode 100644 test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageTests.cs diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/Package.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackage.cs similarity index 50% rename from src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/Package.cs rename to src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackage.cs index fd6cc8ec057..ff78230c74f 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/Package.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackage.cs @@ -9,60 +9,89 @@ using System.Diagnostics.CodeAnalysis; using NuGet.Versioning; -namespace NuGet.CommandLine.XPlat.Commands.Package.Update +namespace NuGet.CommandLine.XPlat.Commands.Package { - internal record Package : IEqualityComparer + internal record NuGetPackage : IEqualityComparer { public required string Id { get; init; } - public required VersionRange? VersionRange { get; init; } + public VersionRange? VersionRange { get; init; } - internal static IReadOnlyList Parse(ArgumentResult result) + public NuGetVersion? ExactVersion { get; init; } + + internal static IReadOnlyList ParsePackagesWithVersionRange(ArgumentResult result) + { + return ParsePackages(result, exactVersion: false); + } + + internal static IReadOnlyList ParsePackagesWithExactVersions(ArgumentResult result) + { + return ParsePackages(result, exactVersion: true); + } + + private static IReadOnlyList ParsePackages(ArgumentResult result, bool exactVersion) { if (result.Tokens.Count == 0) { return []; } - List packages = new List(result.Tokens.Count); + List packages = new List(result.Tokens.Count); foreach (var token in result.Tokens) { string? packageId; - VersionRange? newVersion; + VersionRange? newVersionRange = null; + NuGetVersion? newExactVersion = null; + int separatorIndex = token.Value.IndexOf('@'); + if (separatorIndex < 0) { packageId = token.Value; - newVersion = null; } else { packageId = token.Value.Substring(0, separatorIndex); string versionString = token.Value.Substring(separatorIndex + 1); + if (string.IsNullOrEmpty(versionString)) { result.AddError(Messages.Error_MissingVersion(token.Value)); return []; } - if (!VersionRange.TryParse(versionString, out newVersion)) + + if (exactVersion) { - result.AddError(Messages.Error_InvalidVersionRange(versionString)); - return []; + if (!NuGetVersion.TryParse(versionString, out newExactVersion)) + { + result.AddError(Messages.Error_InvalidVersion(versionString)); + return []; + } + } + else + { + if (!VersionRange.TryParse(versionString, out newVersionRange)) + { + result.AddError(Messages.Error_InvalidVersionRange(versionString)); + return []; + } } } - var package = new Package + NuGetPackage package = new NuGetPackage { Id = packageId, - VersionRange = newVersion + VersionRange = newVersionRange, + ExactVersion = newExactVersion }; + packages.Add(package); } return packages; } - public bool Equals(Package? x, Package? y) + public bool Equals(NuGetPackage? x, NuGetPackage? y) { if (ReferenceEquals(x, y)) { @@ -79,14 +108,16 @@ public bool Equals(Package? x, Package? y) return false; } - return VersionRangeComparer.Default.Equals(x.VersionRange, y.VersionRange); + return VersionRangeComparer.Default.Equals(x.VersionRange, y.VersionRange) && + VersionComparer.Compare(x.ExactVersion, y.ExactVersion, VersionComparison.Default) == 0; } - public int GetHashCode([DisallowNull] Package obj) + public int GetHashCode([DisallowNull] NuGetPackage obj) { HashCode hash = new HashCode(); hash.Add(obj.Id, StringComparer.OrdinalIgnoreCase); hash.Add(obj.VersionRange); + hash.Add(obj.ExactVersion); return hash.ToHashCode(); } } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs index e99e5edfd0c..07374e06af8 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs @@ -12,7 +12,7 @@ internal record PackageUpdateArgs { public required string Project { get; init; } - public required IReadOnlyList Packages { get; init; } + public required IReadOnlyList Packages { get; init; } public required bool Interactive { get; init; } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs index f2e2b12e624..79dac41430c 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs @@ -24,11 +24,11 @@ internal static void Register(Command packageCommand, Option interactiveOp { var command = new DocumentedCommand("update", Strings.PackageUpdateCommand_Description, "https://aka.ms/dotnet/package/update"); - var packagesArguments = new Argument>("packages") + var packagesArguments = new Argument>("packages") { Description = Strings.PackageUpdate_PackageArgumentDescription, Arity = ArgumentArity.ZeroOrMore, - CustomParser = Package.Parse + CustomParser = NuGetPackage.ParsePackagesWithVersionRange }; command.Arguments.Add(packagesArguments); @@ -49,7 +49,7 @@ internal static void Register(Command packageCommand, Option interactiveOp command.SetAction(async (args, cancellationToken) => { FileSystemInfo? project = args.GetValue(projectOption); - IReadOnlyList packages = args.GetValue(packagesArguments) ?? []; + IReadOnlyList packages = args.GetValue(packagesArguments) ?? []; bool interactive = args.GetValue(interactiveOption); VerbosityEnum verbosity = args.GetValue(verbosityOption) ?? VerbosityEnum.normal; LogLevel logLevel = verbosity.ToLogLevel(); diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs index 06015380454..26bd2161f43 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs @@ -182,7 +182,7 @@ internal static async Task Run(PackageUpdateArgs args, ILoggerWithColor log } private static async Task<(List vulnerablePackages, int packagesScanned)> SelectVulnerablePackagesToUpdateAsync( - IReadOnlyList? packages, + IReadOnlyList? packages, DependencyGraphSpec dgSpec, ILoggerWithColor logger, IPackageUpdateIO packageUpdateIO, @@ -283,7 +283,7 @@ bool PackageHasVulnerability(string packageId, NuGetVersion version, IReadOnlyLi } internal static async Task> SelectPackagesToUpdateAsync( - IReadOnlyList packages, + IReadOnlyList packages, PackageSpec project, ILoggerWithColor logger, IPackageUpdateIO packageUpdateIO, @@ -499,7 +499,7 @@ private static (VersionRange? version, List targetFrameworks) return successful ? (packagesToUpdate, allProjectPackages.Count) : (null, allProjectPackages.Count); } - private static List<(Package identity, List tfms)>? GetAllPackagesReferencedByProject(PackageSpec project, ILoggerWithColor logger) + private static List<(NuGetPackage identity, List tfms)>? GetAllPackagesReferencedByProject(PackageSpec project, ILoggerWithColor logger) { var allPackages = new Dictionary tfms, bool hasError)>(StringComparer.OrdinalIgnoreCase); bool hasErrors = false; @@ -543,10 +543,10 @@ private static (VersionRange? version, List targetFrameworks) return null; } - List<(Package package, List tfms)> result = new(allPackages.Count); + List<(NuGetPackage package, List tfms)> result = new(allPackages.Count); foreach (var kvp in allPackages) { - var package = new Package { Id = kvp.Key, VersionRange = kvp.Value.version }; + var package = new NuGetPackage { Id = kvp.Key, VersionRange = kvp.Value.version }; result.Add((package, kvp.Value.tfms)); } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Messages.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Messages.cs index 4513bc899ce..3675427ac44 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Messages.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Messages.cs @@ -49,6 +49,12 @@ internal static string Error_InvalidVersionRange(string input) return string.Format(CultureInfo.CurrentCulture, Strings.Error_InvalidVersionRange, input); } + /// + internal static string Error_InvalidVersion(string input) + { + return string.Format(CultureInfo.CurrentCulture, Strings.Error_InvalidVersion, input); + } + /// internal static string Error_PackageSourceMappingNotFound(string packageId) { diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs index c29c0d2b84e..78c11df5ff4 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs @@ -19,7 +19,7 @@ namespace NuGet.CommandLine.XPlat { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Strings { @@ -673,6 +673,15 @@ internal static string Error_InvalidSource { } } + /// + /// Looks up a localized string similar to Invalid version value '{0}'. An exact NuGet version is required for this operation.. + /// + internal static string Error_InvalidVersion { + get { + return ResourceManager.GetString("Error_InvalidVersion", resourceCulture); + } + } + /// /// Looks up a localized string similar to Invalid version range '{0}'. /// diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx index ae081369f57..f52bf7d7c5f 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx @@ -1104,4 +1104,8 @@ Do not translate "PackageVersion" Argument cannot be null or empty. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + \ No newline at end of file diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf index 1a2961fce97..9fb1952ebb8 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf @@ -353,6 +353,11 @@ NuGet vyžaduje zdroje HTTPS. Pokud chcete používat zdroje HTTP, musíte v sou Zadaný zdroj {0} není platný. Zadejte platný zdroj. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Neplatný rozsah verzí {0} diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf index 7db30481336..dce6b2ce028 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf @@ -353,6 +353,11 @@ NuGet erfordert HTTPS-Quellen. Um HTTP-Quellen zu verwenden, müssen Sie „allo Die angegebene Quelle "{0}" ist ungültig. Geben Sie eine gültige Quelle an. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Ungültiger Versionsbereich „{0}“ diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf index 16368281dc0..c7b45ef0708 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf @@ -353,6 +353,11 @@ NuGet requiere orígenes HTTPS. Para usar orígenes HTTP, es necesario establece El origen "{0}" especificado no es válido. Proporcione un origen válido. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Intervalo de versiones no válido "{0}" diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf index 9f3113bc24f..28176be8997 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf @@ -353,6 +353,11 @@ NuGet nécessite des sources HTTPS. Pour utiliser des sources HTTP, vous devez d La source spécifiée '{0}' est non valide. Indiquez une source valide. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Étendue de version non valide « {0} » diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf index f66f82bc585..10017f7379f 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf @@ -353,6 +353,11 @@ NuGet richiede origini HTTPS. Per utilizzare origini HTTP, è necessario imposta L'origine '{0}' specificata non è valida. Specificare un'origine valida. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Intervallo versioni non valido '{0}' diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf index 89f094cbac4..f8d3ca60e5b 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf @@ -353,6 +353,11 @@ NuGet には HTTPS ソースが必要です。HTTP ソースを使用するに 指定されたソース '{0}' が正しくありません。有効なソースを指定してください。 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' バージョン範囲 '{0}' が無効です diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf index af440ad2ab5..75a3fd1f50f 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf @@ -353,6 +353,11 @@ NuGet에는 HTTPS 원본이 필요합니다. HTTP 원본을 사용하려면 NuGe 지정된 소스 '{0}'이(가) 올바르지 않습니다. 유효한 소스를 제공하세요. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' 잘못된 버전 범위 '{0}' diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf index 5293728c52d..463a088cf94 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf @@ -353,6 +353,11 @@ Menedżer NuGet wymaga źródeł HTTPS. Aby użyć źródeł HTTP, musisz wyraź Określone źródło „{0}” jest nieprawidłowe. Określ prawidłowe źródło. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Nieprawidłowy zakres wersji „{0}” diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf index 3b1e582a6d2..f52df82251a 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf @@ -353,6 +353,11 @@ O NuGet requer fontes HTTPS. Para usar fontes HTTP, você deve definir explicita A origem especificada '{0}' é inválida. Forneça uma origem válida. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Intervalo de versão "{0}" inválido diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf index 71438cec309..0fa522dc203 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf @@ -353,6 +353,11 @@ NuGet requires HTTPS sources. To use HTTP sources, you must explicitly set 'allo Указанный источник "{0}" является недопустимым. Укажите допустимый источник. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Недопустимый диапазон версий "{0}" diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf index 02b92de82fe..7c613fe8f19 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf @@ -354,6 +354,11 @@ NuGet için HTTPS kaynakları gereklidir. HTTP kaynaklarını kullanmak için Nu Belirtilen '{0}' kaynağı geçersiz. Geçerli bir kaynak belirtin. 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' Geçersiz sürüm aralığı '{0}' diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf index 1de6f867783..719c7c21b99 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf @@ -353,6 +353,11 @@ NuGet 需要 HTTPS 源。要使用 HTTP 源,必须在 NuGet.Config 文件中 指定的源“{0}”无效。请提供有效的源。 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' 版本范围“{0}”无效 diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf index 8649718f00d..75c2473eb66 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf @@ -353,6 +353,11 @@ NuGet 需要 HTTPS 來源。您必須在 NuGet.Config 檔案中將 'allowInsecur 指定的來源 '{0}' 無效。請提供有效的來源。 0 - The invalid source. + + Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. An exact NuGet version is required for this operation. + 0 - package version + Invalid version range '{0}' 不正確版本範圍 '{0}' diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs new file mode 100644 index 00000000000..92190e32753 --- /dev/null +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs @@ -0,0 +1,217 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.CommandLine; +using FluentAssertions; +using NuGet.Versioning; +using Xunit; + +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackage; + +namespace NuGet.CommandLine.Xplat.Tests.Commands.Package +{ + public class NuGetPackageTests + { + private RootCommand _versionRangeCommand; + private RootCommand _exactVersionCommand; + private Argument> _versionRangePackagesArgument; + private Argument> _exactVersionPackagesArgument; + + public NuGetPackageTests() + { + _versionRangeCommand = new RootCommand(); + + _versionRangePackagesArgument = new Argument>("packages") + { + Arity = ArgumentArity.ZeroOrMore, + CustomParser = Pkg.ParsePackagesWithVersionRange + }; + _versionRangeCommand.Arguments.Add(_versionRangePackagesArgument); + + _exactVersionCommand = new RootCommand(); + _exactVersionPackagesArgument = new Argument>("packages") + { + Arity = ArgumentArity.ZeroOrMore, + CustomParser = Pkg.ParsePackagesWithExactVersions + }; + _exactVersionCommand.Arguments.Add(_exactVersionPackagesArgument); + } + + [Fact] + public void ParsePackagesWithVersionRange_OnePackage_ReturnsListOfOne() + { + // Arrange + var result = _versionRangeCommand.Parse("packageId"); + + // Act + var packages = result.GetValue(_versionRangePackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + VersionRange = null + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithVersionRange_TwoPackages_ReturnsListOfTwo() + { + // Arrange + var result = _versionRangeCommand.Parse("packageId1 packageId2"); + + // Act + var packages = result.GetValue(_versionRangePackagesArgument); + + // Assert + IReadOnlyList expects = [ + new Pkg() { Id = "packageId1", VersionRange = null }, + new Pkg() { Id = "packageId2", VersionRange = null } + ]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithVersionRange_PackageWithVersion_ReturnsPackageWithVersion() + { + // Arrange + var result = _versionRangeCommand.Parse("packageId@1.2.3"); + + // Act + var packages = result.GetValue(_versionRangePackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + VersionRange = VersionRange.Parse("1.2.3") + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithVersionRange_PackageWithRangeSyntax_ReturnsPackageWithVersion() + { + // Arrange + var result = _versionRangeCommand.Parse("packageId@[1.2.3,2.0.0)"); + + // Act + var packages = result.GetValue(_versionRangePackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + VersionRange = VersionRange.Parse("[1.2.3,2.0.0)") + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithVersionRange_VersionWithNoId_ReturnsError() + { + // Arrange & Act + var result = _versionRangeCommand.Parse("@1.2.3"); + + // Assert + result.Errors.Should().ContainSingle(); + } + + [Fact] + public void ParsePackagesWithVersionRange_PackageWithInvalidVersion_ReturnsError() + { + // Arrange & Act + var result = _versionRangeCommand.Parse("packageId@one"); + + // Assert + result.Errors.Should().ContainSingle(); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithExactVersion_ReturnsPackageWithExactVersion() + { + // Arrange + var result = _exactVersionCommand.Parse("packageId@1.2.3"); + + // Act + var packages = result.GetValue(_exactVersionPackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + ExactVersion = new NuGetVersion("1.2.3"), + VersionRange = null + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithExactVersions_TwoPackagesWithExactVersions_ReturnsListOfTwo() + { + // Arrange + var result = _exactVersionCommand.Parse("packageId1@1.0.0 packageId2@2.3.4"); + + // Act + var packages = result.GetValue(_exactVersionPackagesArgument); + + // Assert + IReadOnlyList expects = [ + new Pkg() { Id = "packageId1", ExactVersion = new NuGetVersion("1.0.0") }, + new Pkg() { Id = "packageId2", ExactVersion = new NuGetVersion("2.3.4") } + ]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithoutVersion_ReturnsPackageWithNullVersion() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("packageId"); + + // Act + var packages = result.GetValue(_exactVersionPackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + ExactVersion = null, + VersionRange = null + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithExactVersions_VersionWithNoId_ReturnsError() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("@1.2.3"); + + // Assert + result.Errors.Should().ContainSingle(); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithRangeSyntax_ReturnsError() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("packageId@[1.2.3,2.0.0)"); + + // Assert + result.Errors.Should().ContainSingle(); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithInvalidVersion_ReturnsError() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("packageId@one"); + + // Assert + result.Errors.Should().ContainSingle(); + } + } +} diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageTests.cs deleted file mode 100644 index 39d1cbd6418..00000000000 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageTests.cs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.CommandLine; -using FluentAssertions; -using NuGet.Versioning; -using Xunit; - -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.Update.Package; - -namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update -{ - public class PackageTests - { - private RootCommand _command; - private Argument> _packagesArgument; - - public PackageTests() - { - _command = new RootCommand(); - - _packagesArgument = new Argument>("packages") - { - Arity = ArgumentArity.ZeroOrMore, - CustomParser = Pkg.Parse - }; - _command.Arguments.Add(_packagesArgument); - } - - [Fact] - public void Parse_OnePackage_ReturnsListOfOne() - { - // Arrange - var result = _command.Parse("packageId"); - - // Act - var packages = result.GetValue(_packagesArgument); - - // Assert - IReadOnlyList expects = [new Pkg() - { - Id = "packageId", - VersionRange = null - }]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void Parse_TwoPackages_ReturnsListOfTwo() - { - // Arrange - var result = _command.Parse("packageId1 packageId2"); - - // Act - var packages = result.GetValue(_packagesArgument); - - // Assert - IReadOnlyList expects = [ - new Pkg() { Id = "packageId1", VersionRange = null }, - new Pkg() { Id = "packageId2", VersionRange = null } - ]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void Parse_PackageWithVersion_ReturnsPackageWithVersion() - { - // Arrange - var result = _command.Parse("packageId@1.2.3"); - - // Act - var packages = result.GetValue(_packagesArgument); - - // Assert - IReadOnlyList expects = [new Pkg() - { - Id = "packageId", - VersionRange = VersionRange.Parse("1.2.3") - }]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void Parse_PackageWithRangeSyntax_ReturnsPackageWithVersion() - { - // Arrange - var result = _command.Parse("packageId@[1.2.3,2.0.0)"); - - // Act - var packages = result.GetValue(_packagesArgument); - - // Assert - IReadOnlyList expects = [new Pkg() - { - Id = "packageId", - VersionRange = VersionRange.Parse("[1.2.3,2.0.0)") - }]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void Parse_VersionWithNoId_ReturnsError() - { - // Arrange & Act - var result = _command.Parse("@1.2.3"); - - // Assert - result.Errors.Should().ContainSingle(); - } - - [Fact] - public void Parse_PackageWithInvalidVersion_ReturnsError() - { - // Arrange & Act - var result = _command.Parse("packageId@one"); - - // Assert - result.Errors.Should().ContainSingle(); - } - } -} diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs index 26c6e8c901c..26e80309e78 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs @@ -22,7 +22,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.Update.Package; +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackage; public class GetPackageToUpdateTests { diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs index 117b1316b24..b33da4aaaa9 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs @@ -19,7 +19,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = XPlat.Commands.Package.Update.Package; +using Pkg = XPlat.Commands.Package.NuGetPackage; public class MultiProjectTests { diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs index 75e198e8580..14ae8c49d2c 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs @@ -18,7 +18,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = XPlat.Commands.Package.Update.Package; +using Pkg = XPlat.Commands.Package.NuGetPackage; public class SingleProjectTests { From df168ad15ff36b6ebb52612a5af4c9cc796d6240 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Mon, 13 Oct 2025 13:58:26 -0700 Subject: [PATCH 2/3] Seperate records --- .../Package/NuGetPackageWithNuGetVersion.cs | 98 +++++++++++++++ ...age.cs => NuGetPackageWithVersionRange.cs} | 59 +++------ .../Package/Update/PackageUpdateArgs.cs | 2 +- .../Package/Update/PackageUpdateCommand.cs | 6 +- .../Update/PackageUpdateCommandRunner.cs | 10 +- .../NuGetPackageWithNuGetVersionTests.cs | 113 ++++++++++++++++++ ...s => NuGetPackageWithVersionRangeTests.cs} | 103 +--------------- .../GetPackageToUpdateTests.cs | 2 +- .../MultiProjectTests.cs | 2 +- .../SingleProjectTests.cs | 2 +- 10 files changed, 241 insertions(+), 156 deletions(-) create mode 100644 src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs rename src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/{NuGetPackage.cs => NuGetPackageWithVersionRange.cs} (51%) create mode 100644 test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs rename test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/{NuGetPackageTests.cs => NuGetPackageWithVersionRangeTests.cs} (52%) diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs new file mode 100644 index 00000000000..8569cec34da --- /dev/null +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs @@ -0,0 +1,98 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#nullable enable + +using System; +using System.Collections.Generic; +using System.CommandLine.Parsing; +using System.Diagnostics.CodeAnalysis; +using NuGet.Versioning; + +namespace NuGet.CommandLine.XPlat.Commands.Package +{ + internal record NuGetPackageWithNuGetVersion : IEqualityComparer + { + public required string Id { get; init; } + + public NuGetVersion? NuGetVersion { get; init; } + + internal static IReadOnlyList Parse(ArgumentResult result) + { + if (result.Tokens.Count == 0) + { + return []; + } + + var packages = new List(result.Tokens.Count); + + foreach (var token in result.Tokens) + { + string? packageId; + NuGetVersion? newExactVersion = null; + + int separatorIndex = token.Value.IndexOf('@'); + + if (separatorIndex < 0) + { + packageId = token.Value; + } + else + { + packageId = token.Value.Substring(0, separatorIndex); + string versionString = token.Value.Substring(separatorIndex + 1); + + if (string.IsNullOrEmpty(versionString)) + { + result.AddError(Messages.Error_MissingVersion(token.Value)); + return []; + } + + if (!NuGetVersion.TryParse(versionString, out newExactVersion)) + { + result.AddError(Messages.Error_InvalidVersion(versionString)); + return []; + } + } + + var package = new NuGetPackageWithNuGetVersion + { + Id = packageId, + NuGetVersion = newExactVersion + }; + + packages.Add(package); + } + + return packages; + } + + public bool Equals(NuGetPackageWithNuGetVersion? x, NuGetPackageWithNuGetVersion? y) + { + if (ReferenceEquals(x, y)) + { + return true; + } + + if (x is null || y is null) + { + return false; + } + + if (!x.Id.Equals(y.Id, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + return VersionComparer.Compare(x.NuGetVersion, y.NuGetVersion, VersionComparison.Default) == 0; + } + + public int GetHashCode([DisallowNull] NuGetPackageWithNuGetVersion obj) + { + HashCode hash = new HashCode(); + hash.Add(obj.Id, StringComparer.OrdinalIgnoreCase); + hash.Add(obj.NuGetVersion); + return hash.ToHashCode(); + } + } +} diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackage.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithVersionRange.cs similarity index 51% rename from src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackage.cs rename to src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithVersionRange.cs index ff78230c74f..a99efa2b1c0 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackage.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithVersionRange.cs @@ -11,87 +11,58 @@ namespace NuGet.CommandLine.XPlat.Commands.Package { - internal record NuGetPackage : IEqualityComparer + internal record NuGetPackageWithVersionRange : IEqualityComparer { public required string Id { get; init; } - public VersionRange? VersionRange { get; init; } + public required VersionRange? VersionRange { get; init; } - public NuGetVersion? ExactVersion { get; init; } - - internal static IReadOnlyList ParsePackagesWithVersionRange(ArgumentResult result) - { - return ParsePackages(result, exactVersion: false); - } - - internal static IReadOnlyList ParsePackagesWithExactVersions(ArgumentResult result) - { - return ParsePackages(result, exactVersion: true); - } - - private static IReadOnlyList ParsePackages(ArgumentResult result, bool exactVersion) + internal static IReadOnlyList Parse(ArgumentResult result) { if (result.Tokens.Count == 0) { return []; } - List packages = new List(result.Tokens.Count); + List packages = new List(result.Tokens.Count); foreach (var token in result.Tokens) { string? packageId; - VersionRange? newVersionRange = null; - NuGetVersion? newExactVersion = null; - + VersionRange? newVersion; int separatorIndex = token.Value.IndexOf('@'); - if (separatorIndex < 0) { packageId = token.Value; + newVersion = null; } else { packageId = token.Value.Substring(0, separatorIndex); string versionString = token.Value.Substring(separatorIndex + 1); - if (string.IsNullOrEmpty(versionString)) { result.AddError(Messages.Error_MissingVersion(token.Value)); return []; } - - if (exactVersion) + if (!VersionRange.TryParse(versionString, out newVersion)) { - if (!NuGetVersion.TryParse(versionString, out newExactVersion)) - { - result.AddError(Messages.Error_InvalidVersion(versionString)); - return []; - } - } - else - { - if (!VersionRange.TryParse(versionString, out newVersionRange)) - { - result.AddError(Messages.Error_InvalidVersionRange(versionString)); - return []; - } + result.AddError(Messages.Error_InvalidVersionRange(versionString)); + return []; } } - NuGetPackage package = new NuGetPackage + var package = new NuGetPackageWithVersionRange { Id = packageId, - VersionRange = newVersionRange, - ExactVersion = newExactVersion + VersionRange = newVersion }; - packages.Add(package); } return packages; } - public bool Equals(NuGetPackage? x, NuGetPackage? y) + public bool Equals(NuGetPackageWithVersionRange? x, NuGetPackageWithVersionRange? y) { if (ReferenceEquals(x, y)) { @@ -108,16 +79,14 @@ public bool Equals(NuGetPackage? x, NuGetPackage? y) return false; } - return VersionRangeComparer.Default.Equals(x.VersionRange, y.VersionRange) && - VersionComparer.Compare(x.ExactVersion, y.ExactVersion, VersionComparison.Default) == 0; + return VersionRangeComparer.Default.Equals(x.VersionRange, y.VersionRange); } - public int GetHashCode([DisallowNull] NuGetPackage obj) + public int GetHashCode([DisallowNull] NuGetPackageWithVersionRange obj) { HashCode hash = new HashCode(); hash.Add(obj.Id, StringComparer.OrdinalIgnoreCase); hash.Add(obj.VersionRange); - hash.Add(obj.ExactVersion); return hash.ToHashCode(); } } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs index 07374e06af8..056026f26b5 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs @@ -12,7 +12,7 @@ internal record PackageUpdateArgs { public required string Project { get; init; } - public required IReadOnlyList Packages { get; init; } + public required IReadOnlyList Packages { get; init; } public required bool Interactive { get; init; } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs index 79dac41430c..506ed14a4ae 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs @@ -24,11 +24,11 @@ internal static void Register(Command packageCommand, Option interactiveOp { var command = new DocumentedCommand("update", Strings.PackageUpdateCommand_Description, "https://aka.ms/dotnet/package/update"); - var packagesArguments = new Argument>("packages") + var packagesArguments = new Argument>("packages") { Description = Strings.PackageUpdate_PackageArgumentDescription, Arity = ArgumentArity.ZeroOrMore, - CustomParser = NuGetPackage.ParsePackagesWithVersionRange + CustomParser = NuGetPackageWithVersionRange.Parse }; command.Arguments.Add(packagesArguments); @@ -49,7 +49,7 @@ internal static void Register(Command packageCommand, Option interactiveOp command.SetAction(async (args, cancellationToken) => { FileSystemInfo? project = args.GetValue(projectOption); - IReadOnlyList packages = args.GetValue(packagesArguments) ?? []; + IReadOnlyList packages = args.GetValue(packagesArguments) ?? []; bool interactive = args.GetValue(interactiveOption); VerbosityEnum verbosity = args.GetValue(verbosityOption) ?? VerbosityEnum.normal; LogLevel logLevel = verbosity.ToLogLevel(); diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs index 26bd2161f43..df93e99fa04 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs @@ -182,7 +182,7 @@ internal static async Task Run(PackageUpdateArgs args, ILoggerWithColor log } private static async Task<(List vulnerablePackages, int packagesScanned)> SelectVulnerablePackagesToUpdateAsync( - IReadOnlyList? packages, + IReadOnlyList? packages, DependencyGraphSpec dgSpec, ILoggerWithColor logger, IPackageUpdateIO packageUpdateIO, @@ -283,7 +283,7 @@ bool PackageHasVulnerability(string packageId, NuGetVersion version, IReadOnlyLi } internal static async Task> SelectPackagesToUpdateAsync( - IReadOnlyList packages, + IReadOnlyList packages, PackageSpec project, ILoggerWithColor logger, IPackageUpdateIO packageUpdateIO, @@ -499,7 +499,7 @@ private static (VersionRange? version, List targetFrameworks) return successful ? (packagesToUpdate, allProjectPackages.Count) : (null, allProjectPackages.Count); } - private static List<(NuGetPackage identity, List tfms)>? GetAllPackagesReferencedByProject(PackageSpec project, ILoggerWithColor logger) + private static List<(NuGetPackageWithVersionRange identity, List tfms)>? GetAllPackagesReferencedByProject(PackageSpec project, ILoggerWithColor logger) { var allPackages = new Dictionary tfms, bool hasError)>(StringComparer.OrdinalIgnoreCase); bool hasErrors = false; @@ -543,10 +543,10 @@ private static (VersionRange? version, List targetFrameworks) return null; } - List<(NuGetPackage package, List tfms)> result = new(allPackages.Count); + List<(NuGetPackageWithVersionRange package, List tfms)> result = new(allPackages.Count); foreach (var kvp in allPackages) { - var package = new NuGetPackage { Id = kvp.Key, VersionRange = kvp.Value.version }; + var package = new NuGetPackageWithVersionRange { Id = kvp.Key, VersionRange = kvp.Value.version }; result.Add((package, kvp.Value.tfms)); } diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs new file mode 100644 index 00000000000..b667d4e1457 --- /dev/null +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs @@ -0,0 +1,113 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.CommandLine; +using FluentAssertions; +using NuGet.Versioning; +using Xunit; + +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackageWithNuGetVersion; + +namespace NuGet.CommandLine.Xplat.Tests.Commands.Package +{ + public class NuGetPackageWithNuGetVersionTests + { + private RootCommand _exactVersionCommand; + private Argument> _exactVersionPackagesArgument; + + public NuGetPackageWithNuGetVersionTests() + { + _exactVersionCommand = new RootCommand(); + _exactVersionPackagesArgument = new Argument>("packages") + { + Arity = ArgumentArity.ZeroOrMore, + CustomParser = Pkg.Parse + }; + _exactVersionCommand.Arguments.Add(_exactVersionPackagesArgument); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithExactVersion_ReturnsPackageWithExactVersion() + { + // Arrange + var result = _exactVersionCommand.Parse("packageId@1.2.3"); + + // Act + var packages = result.GetValue(_exactVersionPackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + NuGetVersion = new NuGetVersion("1.2.3"), + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithExactVersions_TwoPackagesWithExactVersions_ReturnsListOfTwo() + { + // Arrange + var result = _exactVersionCommand.Parse("packageId1@1.0.0 packageId2@2.3.4"); + + // Act + var packages = result.GetValue(_exactVersionPackagesArgument); + + // Assert + IReadOnlyList expects = [ + new Pkg() { Id = "packageId1", NuGetVersion = new NuGetVersion("1.0.0") }, + new Pkg() { Id = "packageId2", NuGetVersion = new NuGetVersion("2.3.4") } + ]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithoutVersion_ReturnsPackageWithNullVersion() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("packageId"); + + // Act + var packages = result.GetValue(_exactVersionPackagesArgument); + + // Assert + IReadOnlyList expects = [new Pkg() + { + Id = "packageId", + NuGetVersion = null, + }]; + packages.Should().BeEquivalentTo(expects); + } + + [Fact] + public void ParsePackagesWithExactVersions_VersionWithNoId_ReturnsError() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("@1.2.3"); + + // Assert + result.Errors.Should().ContainSingle(); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithRangeSyntax_ReturnsError() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("packageId@[1.2.3,2.0.0)"); + + // Assert + result.Errors.Should().ContainSingle(); + } + + [Fact] + public void ParsePackagesWithExactVersions_PackageWithInvalidVersion_ReturnsError() + { + // Arrange & Act + var result = _exactVersionCommand.Parse("packageId@one"); + + // Assert + result.Errors.Should().ContainSingle(); + } + } +} diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithVersionRangeTests.cs similarity index 52% rename from test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs rename to test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithVersionRangeTests.cs index 92190e32753..670941ae855 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithVersionRangeTests.cs @@ -7,35 +7,25 @@ using NuGet.Versioning; using Xunit; -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackage; +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackageWithVersionRange; namespace NuGet.CommandLine.Xplat.Tests.Commands.Package { - public class NuGetPackageTests + public class NuGetPackageWithVersionRangeTests { private RootCommand _versionRangeCommand; - private RootCommand _exactVersionCommand; private Argument> _versionRangePackagesArgument; - private Argument> _exactVersionPackagesArgument; - public NuGetPackageTests() + public NuGetPackageWithVersionRangeTests() { _versionRangeCommand = new RootCommand(); _versionRangePackagesArgument = new Argument>("packages") { Arity = ArgumentArity.ZeroOrMore, - CustomParser = Pkg.ParsePackagesWithVersionRange + CustomParser = Pkg.Parse }; _versionRangeCommand.Arguments.Add(_versionRangePackagesArgument); - - _exactVersionCommand = new RootCommand(); - _exactVersionPackagesArgument = new Argument>("packages") - { - Arity = ArgumentArity.ZeroOrMore, - CustomParser = Pkg.ParsePackagesWithExactVersions - }; - _exactVersionCommand.Arguments.Add(_exactVersionPackagesArgument); } [Fact] @@ -128,90 +118,5 @@ public void ParsePackagesWithVersionRange_PackageWithInvalidVersion_ReturnsError // Assert result.Errors.Should().ContainSingle(); } - - [Fact] - public void ParsePackagesWithExactVersions_PackageWithExactVersion_ReturnsPackageWithExactVersion() - { - // Arrange - var result = _exactVersionCommand.Parse("packageId@1.2.3"); - - // Act - var packages = result.GetValue(_exactVersionPackagesArgument); - - // Assert - IReadOnlyList expects = [new Pkg() - { - Id = "packageId", - ExactVersion = new NuGetVersion("1.2.3"), - VersionRange = null - }]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void ParsePackagesWithExactVersions_TwoPackagesWithExactVersions_ReturnsListOfTwo() - { - // Arrange - var result = _exactVersionCommand.Parse("packageId1@1.0.0 packageId2@2.3.4"); - - // Act - var packages = result.GetValue(_exactVersionPackagesArgument); - - // Assert - IReadOnlyList expects = [ - new Pkg() { Id = "packageId1", ExactVersion = new NuGetVersion("1.0.0") }, - new Pkg() { Id = "packageId2", ExactVersion = new NuGetVersion("2.3.4") } - ]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void ParsePackagesWithExactVersions_PackageWithoutVersion_ReturnsPackageWithNullVersion() - { - // Arrange & Act - var result = _exactVersionCommand.Parse("packageId"); - - // Act - var packages = result.GetValue(_exactVersionPackagesArgument); - - // Assert - IReadOnlyList expects = [new Pkg() - { - Id = "packageId", - ExactVersion = null, - VersionRange = null - }]; - packages.Should().BeEquivalentTo(expects); - } - - [Fact] - public void ParsePackagesWithExactVersions_VersionWithNoId_ReturnsError() - { - // Arrange & Act - var result = _exactVersionCommand.Parse("@1.2.3"); - - // Assert - result.Errors.Should().ContainSingle(); - } - - [Fact] - public void ParsePackagesWithExactVersions_PackageWithRangeSyntax_ReturnsError() - { - // Arrange & Act - var result = _exactVersionCommand.Parse("packageId@[1.2.3,2.0.0)"); - - // Assert - result.Errors.Should().ContainSingle(); - } - - [Fact] - public void ParsePackagesWithExactVersions_PackageWithInvalidVersion_ReturnsError() - { - // Arrange & Act - var result = _exactVersionCommand.Parse("packageId@one"); - - // Assert - result.Errors.Should().ContainSingle(); - } } } diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs index 26e80309e78..064059d441d 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs @@ -22,7 +22,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackage; +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackageWithVersionRange; public class GetPackageToUpdateTests { diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs index b33da4aaaa9..43baf95cb90 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs @@ -19,7 +19,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = XPlat.Commands.Package.NuGetPackage; +using Pkg = XPlat.Commands.Package.NuGetPackageWithVersionRange; public class MultiProjectTests { diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs index 14ae8c49d2c..2243e83552c 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs @@ -18,7 +18,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = XPlat.Commands.Package.NuGetPackage; +using Pkg = XPlat.Commands.Package.NuGetPackageWithVersionRange; public class SingleProjectTests { From 422090d7bdd20d45756df61defb416b1f9158e47 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Mon, 13 Oct 2025 14:52:22 -0700 Subject: [PATCH 3/3] Clean up --- ...tVersion.cs => PackageWithNuGetVersion.cs} | 38 +------- ...ionRange.cs => PackageWithVersionRange.cs} | 12 +-- .../Package/Update/PackageUpdateArgs.cs | 2 +- .../Package/Update/PackageUpdateCommand.cs | 6 +- .../Update/PackageUpdateCommandRunner.cs | 10 +-- .../Strings.Designer.cs | 2 +- .../NuGet.CommandLine.XPlat/Strings.resx | 2 +- .../xlf/Strings.cs.xlf | 4 +- .../xlf/Strings.de.xlf | 4 +- .../xlf/Strings.es.xlf | 4 +- .../xlf/Strings.fr.xlf | 4 +- .../xlf/Strings.it.xlf | 4 +- .../xlf/Strings.ja.xlf | 4 +- .../xlf/Strings.ko.xlf | 4 +- .../xlf/Strings.pl.xlf | 4 +- .../xlf/Strings.pt-BR.xlf | 4 +- .../xlf/Strings.ru.xlf | 4 +- .../xlf/Strings.tr.xlf | 4 +- .../xlf/Strings.zh-Hans.xlf | 4 +- .../xlf/Strings.zh-Hant.xlf | 4 +- ...sts.cs => PackageWithNuGetVersionTests.cs} | 90 +++++++++++++++++-- ...sts.cs => PackageWithVersionRangeTests.cs} | 48 +++++----- .../GetPackageToUpdateTests.cs | 2 +- .../MultiProjectTests.cs | 2 +- .../SingleProjectTests.cs | 2 +- 25 files changed, 155 insertions(+), 113 deletions(-) rename src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/{NuGetPackageWithNuGetVersion.cs => PackageWithNuGetVersion.cs} (59%) rename src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/{NuGetPackageWithVersionRange.cs => PackageWithVersionRange.cs} (82%) rename test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/{NuGetPackageWithNuGetVersionTests.cs => PackageWithNuGetVersionTests.cs} (53%) rename test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/{NuGetPackageWithVersionRangeTests.cs => PackageWithVersionRangeTests.cs} (54%) diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/PackageWithNuGetVersion.cs similarity index 59% rename from src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs rename to src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/PackageWithNuGetVersion.cs index 8569cec34da..6859ccc6db2 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithNuGetVersion.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/PackageWithNuGetVersion.cs @@ -3,28 +3,26 @@ #nullable enable -using System; using System.Collections.Generic; using System.CommandLine.Parsing; -using System.Diagnostics.CodeAnalysis; using NuGet.Versioning; namespace NuGet.CommandLine.XPlat.Commands.Package { - internal record NuGetPackageWithNuGetVersion : IEqualityComparer + internal record PackageWithNuGetVersion { public required string Id { get; init; } public NuGetVersion? NuGetVersion { get; init; } - internal static IReadOnlyList Parse(ArgumentResult result) + internal static IReadOnlyList Parse(ArgumentResult result) { if (result.Tokens.Count == 0) { return []; } - var packages = new List(result.Tokens.Count); + var packages = new List(result.Tokens.Count); foreach (var token in result.Tokens) { @@ -55,7 +53,7 @@ internal static IReadOnlyList Parse(ArgumentResult } } - var package = new NuGetPackageWithNuGetVersion + var package = new PackageWithNuGetVersion { Id = packageId, NuGetVersion = newExactVersion @@ -66,33 +64,5 @@ internal static IReadOnlyList Parse(ArgumentResult return packages; } - - public bool Equals(NuGetPackageWithNuGetVersion? x, NuGetPackageWithNuGetVersion? y) - { - if (ReferenceEquals(x, y)) - { - return true; - } - - if (x is null || y is null) - { - return false; - } - - if (!x.Id.Equals(y.Id, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - return VersionComparer.Compare(x.NuGetVersion, y.NuGetVersion, VersionComparison.Default) == 0; - } - - public int GetHashCode([DisallowNull] NuGetPackageWithNuGetVersion obj) - { - HashCode hash = new HashCode(); - hash.Add(obj.Id, StringComparer.OrdinalIgnoreCase); - hash.Add(obj.NuGetVersion); - return hash.ToHashCode(); - } } } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithVersionRange.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/PackageWithVersionRange.cs similarity index 82% rename from src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithVersionRange.cs rename to src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/PackageWithVersionRange.cs index a99efa2b1c0..d4060bcca32 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/NuGetPackageWithVersionRange.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/PackageWithVersionRange.cs @@ -11,19 +11,19 @@ namespace NuGet.CommandLine.XPlat.Commands.Package { - internal record NuGetPackageWithVersionRange : IEqualityComparer + internal record PackageWithVersionRange : IEqualityComparer { public required string Id { get; init; } public required VersionRange? VersionRange { get; init; } - internal static IReadOnlyList Parse(ArgumentResult result) + internal static IReadOnlyList Parse(ArgumentResult result) { if (result.Tokens.Count == 0) { return []; } - List packages = new List(result.Tokens.Count); + List packages = new List(result.Tokens.Count); foreach (var token in result.Tokens) { @@ -51,7 +51,7 @@ internal static IReadOnlyList Parse(ArgumentResult } } - var package = new NuGetPackageWithVersionRange + var package = new PackageWithVersionRange { Id = packageId, VersionRange = newVersion @@ -62,7 +62,7 @@ internal static IReadOnlyList Parse(ArgumentResult return packages; } - public bool Equals(NuGetPackageWithVersionRange? x, NuGetPackageWithVersionRange? y) + public bool Equals(PackageWithVersionRange? x, PackageWithVersionRange? y) { if (ReferenceEquals(x, y)) { @@ -82,7 +82,7 @@ public bool Equals(NuGetPackageWithVersionRange? x, NuGetPackageWithVersionRange return VersionRangeComparer.Default.Equals(x.VersionRange, y.VersionRange); } - public int GetHashCode([DisallowNull] NuGetPackageWithVersionRange obj) + public int GetHashCode([DisallowNull] PackageWithVersionRange obj) { HashCode hash = new HashCode(); hash.Add(obj.Id, StringComparer.OrdinalIgnoreCase); diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs index 056026f26b5..79da54e4a16 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateArgs.cs @@ -12,7 +12,7 @@ internal record PackageUpdateArgs { public required string Project { get; init; } - public required IReadOnlyList Packages { get; init; } + public required IReadOnlyList Packages { get; init; } public required bool Interactive { get; init; } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs index 506ed14a4ae..abced3c62f8 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommand.cs @@ -24,11 +24,11 @@ internal static void Register(Command packageCommand, Option interactiveOp { var command = new DocumentedCommand("update", Strings.PackageUpdateCommand_Description, "https://aka.ms/dotnet/package/update"); - var packagesArguments = new Argument>("packages") + var packagesArguments = new Argument>("packages") { Description = Strings.PackageUpdate_PackageArgumentDescription, Arity = ArgumentArity.ZeroOrMore, - CustomParser = NuGetPackageWithVersionRange.Parse + CustomParser = PackageWithVersionRange.Parse }; command.Arguments.Add(packagesArguments); @@ -49,7 +49,7 @@ internal static void Register(Command packageCommand, Option interactiveOp command.SetAction(async (args, cancellationToken) => { FileSystemInfo? project = args.GetValue(projectOption); - IReadOnlyList packages = args.GetValue(packagesArguments) ?? []; + IReadOnlyList packages = args.GetValue(packagesArguments) ?? []; bool interactive = args.GetValue(interactiveOption); VerbosityEnum verbosity = args.GetValue(verbosityOption) ?? VerbosityEnum.normal; LogLevel logLevel = verbosity.ToLogLevel(); diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs index df93e99fa04..6aa29265b50 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Update/PackageUpdateCommandRunner.cs @@ -182,7 +182,7 @@ internal static async Task Run(PackageUpdateArgs args, ILoggerWithColor log } private static async Task<(List vulnerablePackages, int packagesScanned)> SelectVulnerablePackagesToUpdateAsync( - IReadOnlyList? packages, + IReadOnlyList? packages, DependencyGraphSpec dgSpec, ILoggerWithColor logger, IPackageUpdateIO packageUpdateIO, @@ -283,7 +283,7 @@ bool PackageHasVulnerability(string packageId, NuGetVersion version, IReadOnlyLi } internal static async Task> SelectPackagesToUpdateAsync( - IReadOnlyList packages, + IReadOnlyList packages, PackageSpec project, ILoggerWithColor logger, IPackageUpdateIO packageUpdateIO, @@ -499,7 +499,7 @@ private static (VersionRange? version, List targetFrameworks) return successful ? (packagesToUpdate, allProjectPackages.Count) : (null, allProjectPackages.Count); } - private static List<(NuGetPackageWithVersionRange identity, List tfms)>? GetAllPackagesReferencedByProject(PackageSpec project, ILoggerWithColor logger) + private static List<(PackageWithVersionRange identity, List tfms)>? GetAllPackagesReferencedByProject(PackageSpec project, ILoggerWithColor logger) { var allPackages = new Dictionary tfms, bool hasError)>(StringComparer.OrdinalIgnoreCase); bool hasErrors = false; @@ -543,10 +543,10 @@ private static (VersionRange? version, List targetFrameworks) return null; } - List<(NuGetPackageWithVersionRange package, List tfms)> result = new(allPackages.Count); + List<(PackageWithVersionRange package, List tfms)> result = new(allPackages.Count); foreach (var kvp in allPackages) { - var package = new NuGetPackageWithVersionRange { Id = kvp.Key, VersionRange = kvp.Value.version }; + var package = new PackageWithVersionRange { Id = kvp.Key, VersionRange = kvp.Value.version }; result.Add((package, kvp.Value.tfms)); } diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs index 78c11df5ff4..467fe9b47b9 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs @@ -674,7 +674,7 @@ internal static string Error_InvalidSource { } /// - /// Looks up a localized string similar to Invalid version value '{0}'. An exact NuGet version is required for this operation.. + /// Looks up a localized string similar to Invalid version value '{0}'.. /// internal static string Error_InvalidVersion { get { diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx index f52bf7d7c5f..9065e0a4da7 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx @@ -1105,7 +1105,7 @@ Do not translate "PackageVersion" Argument cannot be null or empty. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. 0 - package version \ No newline at end of file diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf index 9fb1952ebb8..4ab265ee684 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf @@ -354,8 +354,8 @@ NuGet vyžaduje zdroje HTTPS. Pokud chcete používat zdroje HTTP, musíte v sou 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf index dce6b2ce028..694d7433b88 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf @@ -354,8 +354,8 @@ NuGet erfordert HTTPS-Quellen. Um HTTP-Quellen zu verwenden, müssen Sie „allo 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf index c7b45ef0708..df23ef140b8 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf @@ -354,8 +354,8 @@ NuGet requiere orígenes HTTPS. Para usar orígenes HTTP, es necesario establece 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf index 28176be8997..82f8fb778b1 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf @@ -354,8 +354,8 @@ NuGet nécessite des sources HTTPS. Pour utiliser des sources HTTP, vous devez d 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf index 10017f7379f..e4eafe258ea 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf @@ -354,8 +354,8 @@ NuGet richiede origini HTTPS. Per utilizzare origini HTTP, è necessario imposta 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf index f8d3ca60e5b..b59fae6677c 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf @@ -354,8 +354,8 @@ NuGet には HTTPS ソースが必要です。HTTP ソースを使用するに 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf index 75a3fd1f50f..49021d131a1 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf @@ -354,8 +354,8 @@ NuGet에는 HTTPS 원본이 필요합니다. HTTP 원본을 사용하려면 NuGe 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf index 463a088cf94..3973ba7aced 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf @@ -354,8 +354,8 @@ Menedżer NuGet wymaga źródeł HTTPS. Aby użyć źródeł HTTP, musisz wyraź 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf index f52df82251a..d39fd35c62e 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf @@ -354,8 +354,8 @@ O NuGet requer fontes HTTPS. Para usar fontes HTTP, você deve definir explicita 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf index 0fa522dc203..0c2ceb27912 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf @@ -354,8 +354,8 @@ NuGet requires HTTPS sources. To use HTTP sources, you must explicitly set 'allo 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf index 7c613fe8f19..3fc1b6b3dc4 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf @@ -355,8 +355,8 @@ NuGet için HTTPS kaynakları gereklidir. HTTP kaynaklarını kullanmak için Nu 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf index 719c7c21b99..d72727b90e9 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf @@ -354,8 +354,8 @@ NuGet 需要 HTTPS 源。要使用 HTTP 源,必须在 NuGet.Config 文件中 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf index 75c2473eb66..1e8ca73ed77 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf @@ -354,8 +354,8 @@ NuGet 需要 HTTPS 來源。您必須在 NuGet.Config 檔案中將 'allowInsecur 0 - The invalid source. - Invalid version value '{0}'. An exact NuGet version is required for this operation. - Invalid version value '{0}'. An exact NuGet version is required for this operation. + Invalid version value '{0}'. + Invalid version value '{0}'. 0 - package version diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/PackageWithNuGetVersionTests.cs similarity index 53% rename from test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs rename to test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/PackageWithNuGetVersionTests.cs index b667d4e1457..7ed2bab98e2 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithNuGetVersionTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/PackageWithNuGetVersionTests.cs @@ -7,16 +7,16 @@ using NuGet.Versioning; using Xunit; -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackageWithNuGetVersion; +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.PackageWithNuGetVersion; namespace NuGet.CommandLine.Xplat.Tests.Commands.Package { - public class NuGetPackageWithNuGetVersionTests + public class PackageWithNuGetVersionTests { private RootCommand _exactVersionCommand; private Argument> _exactVersionPackagesArgument; - public NuGetPackageWithNuGetVersionTests() + public PackageWithNuGetVersionTests() { _exactVersionCommand = new RootCommand(); _exactVersionPackagesArgument = new Argument>("packages") @@ -28,7 +28,7 @@ public NuGetPackageWithNuGetVersionTests() } [Fact] - public void ParsePackagesWithExactVersions_PackageWithExactVersion_ReturnsPackageWithExactVersion() + public void Parse_PackageWithExactVersion_ReturnsPackageWithExactVersion() { // Arrange var result = _exactVersionCommand.Parse("packageId@1.2.3"); @@ -46,7 +46,7 @@ public void ParsePackagesWithExactVersions_PackageWithExactVersion_ReturnsPackag } [Fact] - public void ParsePackagesWithExactVersions_TwoPackagesWithExactVersions_ReturnsListOfTwo() + public void Parse_TwoPackagesWithExactVersions_ReturnsListOfTwo() { // Arrange var result = _exactVersionCommand.Parse("packageId1@1.0.0 packageId2@2.3.4"); @@ -63,7 +63,7 @@ public void ParsePackagesWithExactVersions_TwoPackagesWithExactVersions_ReturnsL } [Fact] - public void ParsePackagesWithExactVersions_PackageWithoutVersion_ReturnsPackageWithNullVersion() + public void Parse_PackageWithoutVersion_ReturnsPackageWithNullVersion() { // Arrange & Act var result = _exactVersionCommand.Parse("packageId"); @@ -81,7 +81,7 @@ public void ParsePackagesWithExactVersions_PackageWithoutVersion_ReturnsPackageW } [Fact] - public void ParsePackagesWithExactVersions_VersionWithNoId_ReturnsError() + public void Parse_VersionWithNoId_ReturnsError() { // Arrange & Act var result = _exactVersionCommand.Parse("@1.2.3"); @@ -91,7 +91,7 @@ public void ParsePackagesWithExactVersions_VersionWithNoId_ReturnsError() } [Fact] - public void ParsePackagesWithExactVersions_PackageWithRangeSyntax_ReturnsError() + public void Parse_PackageWithRangeSyntax_ReturnsError() { // Arrange & Act var result = _exactVersionCommand.Parse("packageId@[1.2.3,2.0.0)"); @@ -101,7 +101,7 @@ public void ParsePackagesWithExactVersions_PackageWithRangeSyntax_ReturnsError() } [Fact] - public void ParsePackagesWithExactVersions_PackageWithInvalidVersion_ReturnsError() + public void Parse_PackageWithInvalidVersion_ReturnsError() { // Arrange & Act var result = _exactVersionCommand.Parse("packageId@one"); @@ -109,5 +109,77 @@ public void ParsePackagesWithExactVersions_PackageWithInvalidVersion_ReturnsErro // Assert result.Errors.Should().ContainSingle(); } + + [Fact] + public void Equals_SameIdAndVersion_ReturnsTrue() + { + // Arrange + var package1 = new Pkg() + { + Id = "packageId", + NuGetVersion = new NuGetVersion("1.2.3"), + }; + var package2 = new Pkg() + { + Id = "packageId", + NuGetVersion = new NuGetVersion("1.2.3"), + }; + // Act & Assert + package1.Should().Be(package2); + } + + [Fact] + public void Equals_DifferentId_ReturnsFalse() + { + // Arrange + var package1 = new Pkg() + { + Id = "packageId1", + NuGetVersion = new NuGetVersion("1.2.3"), + }; + var package2 = new Pkg() + { + Id = "packageId2", + NuGetVersion = new NuGetVersion("1.2.3"), + }; + // Act & Assert + package1.Should().NotBe(package2); + } + + [Fact] + public void Equals_DifferentVersion_ReturnsFalse() + { + // Arrange + var package1 = new Pkg() + { + Id = "packageId", + NuGetVersion = new NuGetVersion("1.2.3"), + }; + var package2 = new Pkg() + { + Id = "packageId", + NuGetVersion = new NuGetVersion("2.0.0"), + }; + // Act & Assert + package1.Should().NotBe(package2); + } + + [Fact] + public void Equals_NullVersionAndNonNullVersion_ReturnsFalse() + { + // Arrange + var package1 = new Pkg() + { + Id = "packageId", + NuGetVersion = null, + }; + var package2 = new Pkg() + { + Id = "packageId", + NuGetVersion = new NuGetVersion("1.0.0"), + }; + // Act & Assert + package1.Should().NotBe(package2); + } } } diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithVersionRangeTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/PackageWithVersionRangeTests.cs similarity index 54% rename from test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithVersionRangeTests.cs rename to test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/PackageWithVersionRangeTests.cs index 670941ae855..bb7372024d7 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/NuGetPackageWithVersionRangeTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/PackageWithVersionRangeTests.cs @@ -7,35 +7,35 @@ using NuGet.Versioning; using Xunit; -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackageWithVersionRange; +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.PackageWithVersionRange; namespace NuGet.CommandLine.Xplat.Tests.Commands.Package { - public class NuGetPackageWithVersionRangeTests + public class PackageWithVersionRangeTests { - private RootCommand _versionRangeCommand; - private Argument> _versionRangePackagesArgument; + private RootCommand _command; + private Argument> _packagesArgument; - public NuGetPackageWithVersionRangeTests() + public PackageWithVersionRangeTests() { - _versionRangeCommand = new RootCommand(); + _command = new RootCommand(); - _versionRangePackagesArgument = new Argument>("packages") + _packagesArgument = new Argument>("packages") { Arity = ArgumentArity.ZeroOrMore, CustomParser = Pkg.Parse }; - _versionRangeCommand.Arguments.Add(_versionRangePackagesArgument); + _command.Arguments.Add(_packagesArgument); } [Fact] - public void ParsePackagesWithVersionRange_OnePackage_ReturnsListOfOne() + public void Parse_OnePackage_ReturnsListOfOne() { // Arrange - var result = _versionRangeCommand.Parse("packageId"); + var result = _command.Parse("packageId"); // Act - var packages = result.GetValue(_versionRangePackagesArgument); + var packages = result.GetValue(_packagesArgument); // Assert IReadOnlyList expects = [new Pkg() @@ -47,13 +47,13 @@ public void ParsePackagesWithVersionRange_OnePackage_ReturnsListOfOne() } [Fact] - public void ParsePackagesWithVersionRange_TwoPackages_ReturnsListOfTwo() + public void Parse_TwoPackages_ReturnsListOfTwo() { // Arrange - var result = _versionRangeCommand.Parse("packageId1 packageId2"); + var result = _command.Parse("packageId1 packageId2"); // Act - var packages = result.GetValue(_versionRangePackagesArgument); + var packages = result.GetValue(_packagesArgument); // Assert IReadOnlyList expects = [ @@ -64,13 +64,13 @@ public void ParsePackagesWithVersionRange_TwoPackages_ReturnsListOfTwo() } [Fact] - public void ParsePackagesWithVersionRange_PackageWithVersion_ReturnsPackageWithVersion() + public void Parse_PackageWithVersion_ReturnsPackageWithVersion() { // Arrange - var result = _versionRangeCommand.Parse("packageId@1.2.3"); + var result = _command.Parse("packageId@1.2.3"); // Act - var packages = result.GetValue(_versionRangePackagesArgument); + var packages = result.GetValue(_packagesArgument); // Assert IReadOnlyList expects = [new Pkg() @@ -82,13 +82,13 @@ public void ParsePackagesWithVersionRange_PackageWithVersion_ReturnsPackageWithV } [Fact] - public void ParsePackagesWithVersionRange_PackageWithRangeSyntax_ReturnsPackageWithVersion() + public void Parse_PackageWithRangeSyntax_ReturnsPackageWithVersion() { // Arrange - var result = _versionRangeCommand.Parse("packageId@[1.2.3,2.0.0)"); + var result = _command.Parse("packageId@[1.2.3,2.0.0)"); // Act - var packages = result.GetValue(_versionRangePackagesArgument); + var packages = result.GetValue(_packagesArgument); // Assert IReadOnlyList expects = [new Pkg() @@ -100,20 +100,20 @@ public void ParsePackagesWithVersionRange_PackageWithRangeSyntax_ReturnsPackageW } [Fact] - public void ParsePackagesWithVersionRange_VersionWithNoId_ReturnsError() + public void Parse_VersionWithNoId_ReturnsError() { // Arrange & Act - var result = _versionRangeCommand.Parse("@1.2.3"); + var result = _command.Parse("@1.2.3"); // Assert result.Errors.Should().ContainSingle(); } [Fact] - public void ParsePackagesWithVersionRange_PackageWithInvalidVersion_ReturnsError() + public void Parse_PackageWithInvalidVersion_ReturnsError() { // Arrange & Act - var result = _versionRangeCommand.Parse("packageId@one"); + var result = _command.Parse("packageId@one"); // Assert result.Errors.Should().ContainSingle(); diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs index 064059d441d..51f3ebc8c32 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/GetPackageToUpdateTests.cs @@ -22,7 +22,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = NuGet.CommandLine.XPlat.Commands.Package.NuGetPackageWithVersionRange; +using Pkg = NuGet.CommandLine.XPlat.Commands.Package.PackageWithVersionRange; public class GetPackageToUpdateTests { diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs index 43baf95cb90..e8ae2b3c660 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/MultiProjectTests.cs @@ -19,7 +19,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = XPlat.Commands.Package.NuGetPackageWithVersionRange; +using Pkg = XPlat.Commands.Package.PackageWithVersionRange; public class MultiProjectTests { diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs index 2243e83552c..f8c5c9dbad0 100644 --- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs +++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Package/Update/PackageUpdateCommandRunnerTests/SingleProjectTests.cs @@ -18,7 +18,7 @@ namespace NuGet.CommandLine.Xplat.Tests.Commands.Package.Update.PackageUpdateCommandRunnerTests; -using Pkg = XPlat.Commands.Package.NuGetPackageWithVersionRange; +using Pkg = XPlat.Commands.Package.PackageWithVersionRange; public class SingleProjectTests {