Skip to content

Commit edaf988

Browse files
Copilotnkolev92
andauthored
Stabilize two PMC package source mapping Apex tests
Agent-Logs-Url: https://github.com/NuGet/NuGet.Client/sessions/69387abc-7df5-4ffa-ba29-f76c06e50ea5 Co-authored-by: nkolev92 <[email protected]>
1 parent 7c7d8ed commit edaf988

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

test/NuGet.Tests.Apex/NuGet.Tests.Apex/NuGetEndToEndTests/NuGetConsoleTestCase.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,32 @@ public async Task UpdatePackageForPC_PackageSourceMapping_WithMultipleFeedsWithI
491491
[DataTestMethod]
492492
[DynamicData(nameof(GetPackagesConfigTemplates), DynamicDataSourceType.Method)]
493493
[Timeout(DefaultTimeout)]
494-
public void InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails(ProjectTemplate projectTemplate)
494+
public async Task InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails(ProjectTemplate projectTemplate)
495495
{
496496
// Arrange
497497
using var simpleTestPathContext = new SimpleTestPathContext();
498-
var privateRepositoryPath = Path.Combine(simpleTestPathContext.SolutionRoot, "PrivateRepository");
498+
var solutionDirectory = simpleTestPathContext.SolutionRoot;
499+
var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");
499500
Directory.CreateDirectory(privateRepositoryPath);
500501

501502
var packageName = "SolutionLevelPkg";
502503
var packageVersion = "1.0.0";
503504

504-
// Package exists in default source but mapping routes Solution* to PrivateRepository where it doesn't exist.
505-
simpleTestPathContext.Settings.AddSource("PrivateRepository", privateRepositoryPath);
506-
simpleTestPathContext.Settings.AddPackageSourceMapping("PrivateRepository", "Solution*");
505+
await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, packageName, packageVersion);
506+
507+
CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
508+
<configuration>
509+
<packageSources>
510+
<clear />
511+
<add key=""LocalRepository"" value=""{simpleTestPathContext.PackageSource}"" />
512+
<add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
513+
</packageSources>
514+
<packageSourceMapping>
515+
<packageSource key=""PrivateRepository"">
516+
<package pattern=""Solution*"" />
517+
</packageSource>
518+
</packageSourceMapping>
519+
</configuration>");
507520

508521
using var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext);
509522
var nugetConsole = GetConsole(testContext.Project);
@@ -524,18 +537,31 @@ public async Task InstallPackageForPC_PackageSourceMapping_WithCorrectSourceOpti
524537
using var simpleTestPathContext = new SimpleTestPathContext();
525538
var solutionDirectory = simpleTestPathContext.SolutionRoot;
526539

540+
var opensourceRepositoryPath = Path.Combine(solutionDirectory, "OpensourceRepository");
541+
Directory.CreateDirectory(opensourceRepositoryPath);
542+
527543
var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");
528544
Directory.CreateDirectory(privateRepositoryPath);
529545

530546
var packageName = "Contoso.MVC.ASP";
531547
var packageVersion = "1.0.0";
532548

533-
// Opensource package in default "source", private package in PrivateRepository
534-
await CommonUtility.CreateNetFrameworkPackageInSourceAsync(simpleTestPathContext.PackageSource, packageName, packageVersion, "Thisisfromopensourcerepo1.txt");
549+
await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion, "Thisisfromopensourcerepo1.txt");
535550
await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersion, "Thisisfromprivaterepo1.txt");
536551

537-
simpleTestPathContext.Settings.AddSource("PrivateRepository", privateRepositoryPath);
538-
simpleTestPathContext.Settings.AddPackageSourceMapping("PrivateRepository", "Contoso.MVC.*");
552+
CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
553+
<configuration>
554+
<packageSources>
555+
<clear />
556+
<add key=""OpensourceRepository"" value=""{opensourceRepositoryPath}"" />
557+
<add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
558+
</packageSources>
559+
<packageSourceMapping>
560+
<packageSource key=""PrivateRepository"">
561+
<package pattern=""Contoso.MVC.*"" />
562+
</packageSource>
563+
</packageSourceMapping>
564+
</configuration>");
539565

540566
using var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext);
541567
var nugetConsole = GetConsole(testContext.Project);

0 commit comments

Comments
 (0)