|
6 | 6 | using Microsoft.DotNet.Cli;
|
7 | 7 | using Microsoft.DotNet.Cli.Commands.NuGet;
|
8 | 8 | using Moq;
|
| 9 | +using Newtonsoft.Json.Linq; |
| 10 | +using NuGet.Versioning; |
9 | 11 |
|
10 | 12 | namespace Microsoft.DotNet.Tools.Run.Tests
|
11 | 13 | {
|
@@ -133,5 +135,51 @@ public void ItHasAWhySubcommand()
|
133 | 135 | .And.NotHaveStdErr()
|
134 | 136 | .And.HaveStdOutContaining("has the following dependency");
|
135 | 137 | }
|
| 138 | + |
| 139 | + [Fact] |
| 140 | + public void ItCanUpdatePackages() |
| 141 | + { |
| 142 | + // Arrange |
| 143 | + var testAssetName = "TestAppSimple"; |
| 144 | + var testAsset = _testAssetsManager |
| 145 | + .CopyTestAsset(testAssetName) |
| 146 | + .WithSource(); |
| 147 | + var projectDirectory = testAsset.Path; |
| 148 | + |
| 149 | + NuGetConfigWriter.Write(projectDirectory, TestContext.Current.TestPackages); |
| 150 | + |
| 151 | + new DotnetCommand(Log, "package", "add", "[email protected]") |
| 152 | + .WithWorkingDirectory(projectDirectory) |
| 153 | + .Execute() |
| 154 | + .Should() |
| 155 | + .Pass() |
| 156 | + .And.NotHaveStdErr(); |
| 157 | + |
| 158 | + // Act |
| 159 | + var commandResult = new DotnetCommand(Log, "package", "update", "dotnet-hello") |
| 160 | + .WithWorkingDirectory(projectDirectory) |
| 161 | + .Execute() |
| 162 | + .Should() |
| 163 | + .Pass() |
| 164 | + .And.NotHaveStdErr(); |
| 165 | + |
| 166 | + // Assert |
| 167 | + var listPackageCommandResult = new DotnetCommand(Log, "package", "list", "--format", "json") |
| 168 | + .WithWorkingDirectory(projectDirectory) |
| 169 | + .Execute(); |
| 170 | + listPackageCommandResult.Should() |
| 171 | + .Pass() |
| 172 | + .And.NotHaveStdErr(); |
| 173 | + |
| 174 | + _ = listPackageCommandResult.StdOut; |
| 175 | + var updatedPackageVersionString = JObject.Parse(listPackageCommandResult.StdOut) |
| 176 | + .SelectToken("$.projects[0].frameworks[0].topLevelPackages[?(@.id == 'dotnet-hello')].requestedVersion") |
| 177 | + .ToString(); |
| 178 | + |
| 179 | + var v1 = NuGetVersion.Parse("1.0.0"); |
| 180 | + var updatedVersion = NuGetVersion.Parse(updatedPackageVersionString); |
| 181 | + |
| 182 | + updatedVersion.Should().BeGreaterThan(v1); |
| 183 | + } |
136 | 184 | }
|
137 | 185 | }
|
0 commit comments