Skip to content

Commit 149339e

Browse files
committed
more test
1 parent b075e4c commit 149339e

1 file changed

Lines changed: 46 additions & 11 deletions

File tree

test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/Package/Download/PackageDownloadRunnerTests.cs

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,56 @@ public async Task RunAsync_NoVersion_PicksHighestAcrossMultipleSources()
204204
File.Exists(Path.Combine(chosen, $"{id.ToLowerInvariant()}.1.2.0.nupkg")).Should().BeTrue();
205205
}
206206

207-
[Fact]
208-
public async Task RunAsync_ExplicitVersionAlreadyInstalled_ShortCircuitsAndSucceeds()
207+
public static IEnumerable<object[]> ShortCircuitsPackageData =>
208+
[
209+
[
210+
new[] {
211+
new PackageWithNuGetVersion()
212+
{
213+
Id = "Contoso.Utils",
214+
NuGetVersion = NuGetVersion.Parse("3.4.5")
215+
}
216+
}
217+
],
218+
[
219+
new[] {
220+
new PackageWithNuGetVersion()
221+
{
222+
Id = "Contoso.Utils",
223+
NuGetVersion = NuGetVersion.Parse("3.4.5")
224+
},
225+
new PackageWithNuGetVersion()
226+
{
227+
Id = "Contoso.Core",
228+
NuGetVersion = NuGetVersion.Parse("3.0.5")
229+
}
230+
}
231+
],
232+
];
233+
234+
[Theory]
235+
[MemberData(nameof(ShortCircuitsPackageData))]
236+
internal async Task RunAsync_ExplicitVersionAlreadyInstalled_ShortCircuitsAndSucceeds(PackageWithNuGetVersion[] packages)
209237
{
210238
// Arrange
211239
using var context = new SimpleTestPathContext();
212240
var sourceDir = context.PackageSource;
213241
var outputDir = context.WorkingDirectory;
214242

215-
var id = "Contoso.Utils";
216-
var v = "3.4.5";
217-
await SimpleTestPackageUtility.CreateFullPackageAsync(sourceDir, id, v);
243+
List<PackageWithNuGetVersion> packagesToInstall = [];
244+
245+
foreach (var package in packages)
246+
{
247+
await SimpleTestPackageUtility.CreateFullPackageAsync(sourceDir, package.Id, package.NuGetVersion.OriginalVersion);
248+
}
218249

219250
var logger = new Mock<ILoggerWithColor>(MockBehavior.Loose);
220251
var settings = new Mock<ISettings>(MockBehavior.Loose);
221252

222253
// First run: install explicit version
223254
var args1 = new PackageDownloadArgs()
224255
{
225-
Packages = [new PackageWithNuGetVersion { Id = id, NuGetVersion = NuGetVersion.Parse(v) }],
256+
Packages = packages,
226257
LogLevel = LogLevel.Verbose,
227258
OutputDirectory = outputDir,
228259
};
@@ -238,7 +269,7 @@ [new PackageSource(sourceDir)],
238269
// Second run: should short-circuit because already installed
239270
var args2 = new PackageDownloadArgs()
240271
{
241-
Packages = [new PackageWithNuGetVersion { Id = id, NuGetVersion = NuGetVersion.Parse(v) }],
272+
Packages = packages,
242273
OutputDirectory = outputDir,
243274
};
244275

@@ -251,10 +282,14 @@ [new PackageSource(sourceDir)],
251282
CancellationToken.None);
252283

253284
// Assert
254-
second.Should().Be(PackageDownloadRunner.ExitCodeSuccess);
255-
var installDir = Path.Combine(outputDir, id.ToLowerInvariant(), v);
256-
Directory.Exists(installDir).Should().BeTrue();
257-
File.Exists(Path.Combine(installDir, $"{id.ToLowerInvariant()}.{v}.nupkg")).Should().BeTrue();
285+
foreach (var package in packages)
286+
{
287+
second.Should().Be(PackageDownloadRunner.ExitCodeSuccess);
288+
var installDir = Path.Combine(outputDir, package.Id.ToLowerInvariant(), package.NuGetVersion.OriginalVersion);
289+
Directory.Exists(installDir).Should().BeTrue();
290+
File.Exists(Path.Combine(installDir, $"{package.Id.ToLowerInvariant()}.{package.NuGetVersion.OriginalVersion}.nupkg")).Should().BeTrue();
291+
}
292+
258293
logger.Verify(l => l.LogMinimal(It.Is<string>(s => s.Contains("Skipping", StringComparison.OrdinalIgnoreCase))), Times.AtLeastOnce);
259294
}
260295

0 commit comments

Comments
 (0)