From c63c000261224beb9067e5c5872e39c4c568b772 Mon Sep 17 00:00:00 2001 From: Xiaotian Gu Date: Mon, 17 Feb 2020 16:44:52 -0500 Subject: [PATCH] added test for cli parameter: versionOverrides --- .../ConsoleArgsParserTests.cs | 17 +++++++++++++++++ .../NuGet.Updater.Tests.csproj | 6 ++++++ .../Resources/version_overrides.json | 4 ++++ .../Arguments/ConsoleArgsContext.cs | 2 +- .../NuGet.Updater.Tool.csproj | 6 ++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/NuGet.Updater.Tests/Resources/version_overrides.json diff --git a/src/NuGet.Updater.Tests/ConsoleArgsParserTests.cs b/src/NuGet.Updater.Tests/ConsoleArgsParserTests.cs index 1123b58..1b26b14 100644 --- a/src/NuGet.Updater.Tests/ConsoleArgsParserTests.cs +++ b/src/NuGet.Updater.Tests/ConsoleArgsParserTests.cs @@ -19,6 +19,7 @@ public class ConsoleArgsParserTests private const string SomeText = nameof(SomeText); private const string SomePublicFeed = "https://pkgs.dev.azure.com/qwe/_packaging/asd/nuget/v3/index.json"; private const string SomePrivateFeed = "https://pkgs.dev.azure.com/qwe/_packaging/asd/nuget/v3/index.json|hunter2"; + private const string PinnedVersionJsonPath = @"Resources\version_overrides.json"; [TestMethod] public void Given_HelpArgument_ContextIsHelp() @@ -156,5 +157,21 @@ public void Given_UpdaterParametersArgument_ContextCollectionPropertyIsSet(Expre var actualValue = collection?.Cast().FirstOrDefault(); Assert.AreEqual(expectedValue, actualValue); } + + [TestMethod] + [DeploymentItem(PinnedVersionJsonPath)] + public void Given_UpdaterParametersArgument_ContextTargetVersionIsSet() + { + var arguments = new[] { "--versionOverrides=" + PinnedVersionJsonPath }; + var context = ConsoleArgsContext.Parse(arguments); + + Assert.IsFalse(context.HasError); + + var actualValues = context.Parameters.VersionOverrides + .ToDictionary(x => x.Key, x => x.Value); + var expectedValues = ConsoleArgsContext.LoadManualOperations(PinnedVersionJsonPath); + + CollectionAssert.AreEqual(expectedValues, actualValues); + } } } diff --git a/src/NuGet.Updater.Tests/NuGet.Updater.Tests.csproj b/src/NuGet.Updater.Tests/NuGet.Updater.Tests.csproj index 6d03a73..4d4e4f1 100644 --- a/src/NuGet.Updater.Tests/NuGet.Updater.Tests.csproj +++ b/src/NuGet.Updater.Tests/NuGet.Updater.Tests.csproj @@ -17,4 +17,10 @@ + + + PreserveNewest + + + diff --git a/src/NuGet.Updater.Tests/Resources/version_overrides.json b/src/NuGet.Updater.Tests/Resources/version_overrides.json new file mode 100644 index 0000000..8c9164d --- /dev/null +++ b/src/NuGet.Updater.Tests/Resources/version_overrides.json @@ -0,0 +1,4 @@ +[ + { "PackageId": "Newtonsoft.Json", "UpdatedVersion": "12.0.1" }, + { "PackageId": "Microsoft.Extensions.Logging", "UpdatedVersion": "3.1.2" } +] diff --git a/src/NuGet.Updater.Tool/Arguments/ConsoleArgsContext.cs b/src/NuGet.Updater.Tool/Arguments/ConsoleArgsContext.cs index 2e671fb..67f97f8 100644 --- a/src/NuGet.Updater.Tool/Arguments/ConsoleArgsContext.cs +++ b/src/NuGet.Updater.Tool/Arguments/ConsoleArgsContext.cs @@ -97,7 +97,7 @@ Action TryParseAndSet(Func parse, Action set) public void WriteOptionDescriptions(TextWriter writer) => CreateOptionsFor(default).WriteOptionDescriptions(writer); - private static Dictionary LoadManualOperations(string inputFilePath) + internal static Dictionary LoadManualOperations(string inputFilePath) { using(var fileReader = File.OpenText(inputFilePath)) using(var jsonReader = new JsonTextReader(fileReader)) diff --git a/src/NuGet.Updater.Tool/NuGet.Updater.Tool.csproj b/src/NuGet.Updater.Tool/NuGet.Updater.Tool.csproj index fcc8cf2..2b2a8e8 100644 --- a/src/NuGet.Updater.Tool/NuGet.Updater.Tool.csproj +++ b/src/NuGet.Updater.Tool/NuGet.Updater.Tool.csproj @@ -35,6 +35,12 @@ + + + <_Parameter1>NuGet.Updater.Tests + + +