Skip to content

Commit

Permalink
added test for cli parameter: versionOverrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaotian Gu committed Feb 17, 2020
1 parent 45861ff commit c63c000
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/NuGet.Updater.Tests/ConsoleArgsParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -156,5 +157,21 @@ public void Given_UpdaterParametersArgument_ContextCollectionPropertyIsSet(Expre
var actualValue = collection?.Cast<object>().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);
}
}
}
6 changes: 6 additions & 0 deletions src/NuGet.Updater.Tests/NuGet.Updater.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
<ProjectReference Include="..\NuGet.Updater.Tool\NuGet.Updater.Tool.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Resources\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/NuGet.Updater.Tests/Resources/version_overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "PackageId": "Newtonsoft.Json", "UpdatedVersion": "12.0.1" },
{ "PackageId": "Microsoft.Extensions.Logging", "UpdatedVersion": "3.1.2" }
]
2 changes: 1 addition & 1 deletion src/NuGet.Updater.Tool/Arguments/ConsoleArgsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Action<string> TryParseAndSet<T>(Func<string, T> parse, Action<T> set)

public void WriteOptionDescriptions(TextWriter writer) => CreateOptionsFor(default).WriteOptionDescriptions(writer);

private static Dictionary<string, NuGetVersion> LoadManualOperations(string inputFilePath)
internal static Dictionary<string, NuGetVersion> LoadManualOperations(string inputFilePath)
{
using(var fileReader = File.OpenText(inputFilePath))
using(var jsonReader = new JsonTextReader(fileReader))
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Updater.Tool/NuGet.Updater.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
</None>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>NuGet.Updater.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<!-- This target ensures the output of the ProjectReferences marked with PrivateAssets="All" are copied to the resulting NuGet package -->
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
Expand Down

0 comments on commit c63c000

Please sign in to comment.