Skip to content

Commit 203f7fa

Browse files
committed
more test
1 parent 149339e commit 203f7fa

1 file changed

Lines changed: 82 additions & 30 deletions

File tree

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

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -206,34 +206,86 @@ public async Task RunAsync_NoVersion_PicksHighestAcrossMultipleSources()
206206

207207
public static IEnumerable<object[]> ShortCircuitsPackageData =>
208208
[
209-
[
210-
new[] {
211-
new PackageWithNuGetVersion()
212-
{
213-
Id = "Contoso.Utils",
214-
NuGetVersion = NuGetVersion.Parse("3.4.5")
215-
}
209+
// single package already installed
210+
[
211+
new []
212+
{
213+
("Contoso.Utils", "3.4.5") // source packages
214+
},
215+
new[]
216+
{
217+
new PackageWithNuGetVersion // argument packages
218+
{
219+
Id = "Contoso.Utils",
220+
NuGetVersion = NuGetVersion.Parse("3.4.5")
216221
}
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-
}
222+
},
223+
new []
224+
{
225+
("Contoso.Utils", "3.4.5") // expected packages
226+
}
227+
],
228+
229+
// multiple packages already installed
230+
[
231+
new []
232+
{
233+
("Contoso.Utils", "3.4.5"), // source packages
234+
("Contoso.Core", "3.0.5")
235+
},
236+
new []
237+
{
238+
new PackageWithNuGetVersion // argument packages
239+
{
240+
Id = "Contoso.Utils",
241+
NuGetVersion = NuGetVersion.Parse("3.4.5")
242+
},
243+
new PackageWithNuGetVersion
244+
{
245+
Id = "Contoso.Core",
246+
NuGetVersion = NuGetVersion.Parse("3.0.5")
230247
}
231-
],
232-
];
248+
},
249+
new []
250+
{
251+
("Contoso.Utils", "3.4.5"), // expected packages
252+
("Contoso.Core", "3.0.5")
253+
}
254+
],
255+
256+
// no version specified, but latest version already installed
257+
[
258+
new []
259+
{
260+
("Contoso.Utils", "3.4.5"), // source packages
261+
("Contoso.Core", "3.0.5")
262+
},
263+
new []
264+
{
265+
new PackageWithNuGetVersion // argument packages
266+
{
267+
Id = "Contoso.Utils",
268+
NuGetVersion = null
269+
},
270+
new PackageWithNuGetVersion
271+
{
272+
Id = "Contoso.Core",
273+
NuGetVersion = null
274+
}
275+
},
276+
new []
277+
{
278+
("Contoso.Utils", "3.4.5"), // expected packages
279+
("Contoso.Core", "3.0.5")
280+
}
281+
]];
233282

234283
[Theory]
235284
[MemberData(nameof(ShortCircuitsPackageData))]
236-
internal async Task RunAsync_ExplicitVersionAlreadyInstalled_ShortCircuitsAndSucceeds(PackageWithNuGetVersion[] packages)
285+
internal async Task RunAsync_VersionAlreadyInstalled_ShortCircuitsAndSucceeds(
286+
IReadOnlyList<(string, string)> sourcePackages,
287+
PackageWithNuGetVersion[] packageDownloadArgs,
288+
IReadOnlyList<(string, string)> expectedPackages)
237289
{
238290
// Arrange
239291
using var context = new SimpleTestPathContext();
@@ -242,9 +294,9 @@ internal async Task RunAsync_ExplicitVersionAlreadyInstalled_ShortCircuitsAndSuc
242294

243295
List<PackageWithNuGetVersion> packagesToInstall = [];
244296

245-
foreach (var package in packages)
297+
foreach (var (id, version) in sourcePackages)
246298
{
247-
await SimpleTestPackageUtility.CreateFullPackageAsync(sourceDir, package.Id, package.NuGetVersion.OriginalVersion);
299+
await SimpleTestPackageUtility.CreateFullPackageAsync(sourceDir, id, version);
248300
}
249301

250302
var logger = new Mock<ILoggerWithColor>(MockBehavior.Loose);
@@ -253,7 +305,7 @@ internal async Task RunAsync_ExplicitVersionAlreadyInstalled_ShortCircuitsAndSuc
253305
// First run: install explicit version
254306
var args1 = new PackageDownloadArgs()
255307
{
256-
Packages = packages,
308+
Packages = packageDownloadArgs,
257309
LogLevel = LogLevel.Verbose,
258310
OutputDirectory = outputDir,
259311
};
@@ -269,7 +321,7 @@ [new PackageSource(sourceDir)],
269321
// Second run: should short-circuit because already installed
270322
var args2 = new PackageDownloadArgs()
271323
{
272-
Packages = packages,
324+
Packages = packageDownloadArgs,
273325
OutputDirectory = outputDir,
274326
};
275327

@@ -282,12 +334,12 @@ [new PackageSource(sourceDir)],
282334
CancellationToken.None);
283335

284336
// Assert
285-
foreach (var package in packages)
337+
foreach (var (id, version) in expectedPackages)
286338
{
287339
second.Should().Be(PackageDownloadRunner.ExitCodeSuccess);
288-
var installDir = Path.Combine(outputDir, package.Id.ToLowerInvariant(), package.NuGetVersion.OriginalVersion);
340+
var installDir = Path.Combine(outputDir, id, version);
289341
Directory.Exists(installDir).Should().BeTrue();
290-
File.Exists(Path.Combine(installDir, $"{package.Id.ToLowerInvariant()}.{package.NuGetVersion.OriginalVersion}.nupkg")).Should().BeTrue();
342+
File.Exists(Path.Combine(installDir, $"{id.ToLowerInvariant()}.{version}.nupkg")).Should().BeTrue();
291343
}
292344

293345
logger.Verify(l => l.LogMinimal(It.Is<string>(s => s.Contains("Skipping", StringComparison.OrdinalIgnoreCase))), Times.AtLeastOnce);

0 commit comments

Comments
 (0)