Skip to content

Commit 7c7d8ed

Browse files
nkolev92Copilot
andcommitted
Use SimpleTestPathContext Settings API instead of raw config files
Replaced CreateConfigurationFile with Settings.AddSource() and Settings.AddPackageSourceMapping() in 4 PMC source mapping tests to preserve SimpleTestPathContext defaults (globalPackagesFolder, etc.). Also reuse the default 'source' feed as the opensource repo where possible. Updated apex-migration skill with config gotcha learning. Co-authored-by: Copilot <[email protected]>
1 parent 8a1031c commit 7c7d8ed

2 files changed

Lines changed: 19 additions & 59 deletions

File tree

.copilot/skills/apex-migration/SKILL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,9 @@ Skip PS tests that:
287287
- **`_pathContext` vs `testContext`**: `IVsServicesTestCase` uses a class-level
288288
`SimpleTestPathContext _pathContext` (initialized in constructor), not per-test `ApexTestContext`.
289289
PMC tests in `NuGetConsoleTestCase` use per-test `ApexTestContext`.
290+
- **Never overwrite `SimpleTestPathContext`'s NuGet.config**: Using `CreateConfigurationFile` to
291+
write a full config replaces defaults like `globalPackagesFolder`, `fallbackPackageFolders`, and
292+
`httpCacheFolder` — causing packages to pollute the user's real global packages folder. Instead
293+
use `simpleTestPathContext.Settings.AddSource()` and `AddPackageSourceMapping()` to layer config
294+
on top of the defaults.
290295

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

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -495,27 +495,15 @@ public void InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails(P
495495
{
496496
// Arrange
497497
using var simpleTestPathContext = new SimpleTestPathContext();
498-
var solutionDirectory = simpleTestPathContext.SolutionRoot;
499-
var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");
498+
var privateRepositoryPath = Path.Combine(simpleTestPathContext.SolutionRoot, "PrivateRepository");
500499
Directory.CreateDirectory(privateRepositoryPath);
501500

502501
var packageName = "SolutionLevelPkg";
503502
var packageVersion = "1.0.0";
504503

505-
// Package exists in PackageSource but mapping routes SolutionLevelPkg to PrivateRepository where it doesn't exist.
506-
CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
507-
<configuration>
508-
<packageSources>
509-
<clear />
510-
<add key=""LocalRepository"" value=""{simpleTestPathContext.PackageSource}"" />
511-
<add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
512-
</packageSources>
513-
<packageSourceMapping>
514-
<packageSource key=""PrivateRepository"">
515-
<package pattern=""Solution*"" />
516-
</packageSource>
517-
</packageSourceMapping>
518-
</configuration>");
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*");
519507

520508
using var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext);
521509
var nugetConsole = GetConsole(testContext.Project);
@@ -536,31 +524,18 @@ public async Task InstallPackageForPC_PackageSourceMapping_WithCorrectSourceOpti
536524
using var simpleTestPathContext = new SimpleTestPathContext();
537525
var solutionDirectory = simpleTestPathContext.SolutionRoot;
538526

539-
var opensourceRepositoryPath = Path.Combine(solutionDirectory, "OpensourceRepository");
540-
Directory.CreateDirectory(opensourceRepositoryPath);
541-
542527
var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");
543528
Directory.CreateDirectory(privateRepositoryPath);
544529

545530
var packageName = "Contoso.MVC.ASP";
546531
var packageVersion = "1.0.0";
547532

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

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

565540
using var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext);
566541
var nugetConsole = GetConsole(testContext.Project);
@@ -594,19 +569,9 @@ public void InstallPackageForPC_PackageSourceMapping_WithWrongSourceOption_Fails
594569
var packageName = "Contoso.MVC.ASP";
595570
var packageVersion = "1.0.0";
596571

597-
CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
598-
<configuration>
599-
<packageSources>
600-
<clear />
601-
<add key=""OpensourceRepository"" value=""{opensourceRepositoryPath}"" />
602-
<add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
603-
</packageSources>
604-
<packageSourceMapping>
605-
<packageSource key=""PrivateRepository"">
606-
<package pattern=""Contoso.MVC.*"" />
607-
</packageSource>
608-
</packageSourceMapping>
609-
</configuration>");
572+
simpleTestPathContext.Settings.AddSource("OpensourceRepository", opensourceRepositoryPath);
573+
simpleTestPathContext.Settings.AddSource("PrivateRepository", privateRepositoryPath);
574+
simpleTestPathContext.Settings.AddPackageSourceMapping("PrivateRepository", "Contoso.MVC.*");
610575

611576
using var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext);
612577
var nugetConsole = GetConsole(testContext.Project);
@@ -642,19 +607,9 @@ public async Task UpdatePackageForPC_PackageSourceMapping_WithCorrectSourceOptio
642607
await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion1, "Thisisfromopensourcerepo1.txt");
643608
await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion2, "Thisisfromopensourcerepo2.txt");
644609

645-
CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
646-
<configuration>
647-
<packageSources>
648-
<clear />
649-
<add key=""OpensourceRepository"" value=""{opensourceRepositoryPath}"" />
650-
<add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
651-
</packageSources>
652-
<packageSourceMapping>
653-
<packageSource key=""PrivateRepository"">
654-
<package pattern=""Contoso.MVC.*"" />
655-
</packageSource>
656-
</packageSourceMapping>
657-
</configuration>");
610+
simpleTestPathContext.Settings.AddSource("OpensourceRepository", opensourceRepositoryPath);
611+
simpleTestPathContext.Settings.AddSource("PrivateRepository", privateRepositoryPath);
612+
simpleTestPathContext.Settings.AddPackageSourceMapping("PrivateRepository", "Contoso.MVC.*");
658613

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

0 commit comments

Comments
 (0)