Skip to content

Migrate Package Source Mapping tests#7308

Draft
nkolev92 wants to merge 6 commits intodevfrom
dev-nkolev92-migratePSMTests
Draft

Migrate Package Source Mapping tests#7308
nkolev92 wants to merge 6 commits intodevfrom
dev-nkolev92-migratePSMTests

Conversation

@nkolev92
Copy link
Copy Markdown
Member

@nkolev92 nkolev92 commented Apr 20, 2026

Bug

Fixes: NuGet/Home#12185

Description

Migrates PowerShell E2E tests from PackageNameSpaceTests.ps1 to C# Apex tests. The feature was renamed from "PackageNameSpace" to "PackageSourceMapping", so new test names reflect the current terminology.

Migration decisions

# PS Test Function Decision Apex Target Notes
1 Test-PackageSourceMappingRestore-WithSingleFeed Deferred [SkipTest]. Restore-on-build test: manually writes packages.config, builds via Build-Solution. Can be migrated using SolutionService.Build() in a follow-up.
2 Test-PackageSourceMappingRestore-WithMultipleFeedsWithIdenticalPackages-RestoresCorrectPackage Deferred [SkipTest]. Same restore-on-build pattern as #1 with two feeds and content-file verification. Can be migrated using SolutionService.Build() in a follow-up.
3 Test-VsPackageInstallerServices-PackageSourceMappingInstall-WithSingleFeed-Succeed Delete (already covered) IVsServicesTestCase.SimpleInstallFromIVsInstaller_PackageSourceMapping_WithSingleFeed Existing Apex test covers the same scenario.
4 Test-VsPackageInstallerServices-PackageSourceMappingInstall-WithSingleFeed-Fails Migrate IVsServicesTestCase.SimpleInstallFromIVsInstaller_PackageSourceMapping_WithMissingMappedSource_Fails Error-path: maps pattern to non-existent source, asserts package NOT installed.
5 Test-VsPackageInstallerServices-PackageSourceMappingInstall-WithMultipleFeedsWithIdenticalPackages-RestoresCorrectPackageWithSpecifiedVersion Delete (already covered) IVsServicesTestCase.SimpleInstallFromIVsInstaller_PackageSourceMapping_WithMultipleFeedsWithIdenticalPackages_InstallsCorrectPackage Existing Apex test covers specified-version install with content file verification.
6 Test-VsPackageInstallerServices-PackageSourceMappingInstall-WithMultipleFeedsWithIdenticalPackages-RestoresCorrectPackageWithLatestVersion Migrate IVsServicesTestCase.SimpleInstallLatestFromIVsInstaller_PackageSourceMapping_WithMultipleFeedsWithIdenticalPackages_InstallsCorrectPackage Latest-version (no version specified) install from mapped source, verifying correct feed via content file.
7 Test-PC-PackageSourceMappingInstall-Succeed Delete (already covered) NuGetConsoleTestCase.InstallPackageForPC_PackageSourceMapping_WithSingleFeed Existing Apex test covers single-feed PMC install.
8 Test-PC-PackageSourceMappingInstall-Fails Migrate NuGetConsoleTestCase.InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails Error-path: two feeds, pattern mapped to wrong feed, asserts PMC error message.
9 Test-PC-PackageSourceMappingInstall-WithCorrectSourceOption-Succeed Migrate NuGetConsoleTestCase.InstallPackageForPC_PackageSourceMapping_WithCorrectSourceOption_InstallsCorrectPackage Uses -Source to install from mapped private feed, verifies content file origin.
10 Test-PC-PackageSourceMappingInstall-WithWrongSourceOption-Fails Migrate NuGetConsoleTestCase.InstallPackageForPC_PackageSourceMapping_WithWrongSourceOption_Fails Error-path: -Source points to unmapped feed, asserts PMC error message.
11 Test-PC-PackageSourceMappingUpdate-WithCorrectSourceOption-Succeed Migrate NuGetConsoleTestCase.UpdatePackageForPC_PackageSourceMapping_WithCorrectSourceOption_UpdatesCorrectPackage Install v1 then update to v2 from mapped source, verifies content file origin.
CreateCustomTestPackage (helper) Keep in PS Still used by tests #1 and #2.

File changes

  • NuGetConsoleTestCase.cs — 4 new PMC tests (tests 8, 9, 10, 11)
  • IVsServicesTestCase.cs — 2 new IVs API tests (tests 4, 6)
  • PackageNameSpaceTests.ps1 — Deleted 9 functions (tests 3-11), kept tests 1-2 and helper
  • SKILL.md — Updated Apex migration skill with learnings

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

nkolev92 and others added 2 commits April 20, 2026 14:33
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]>
[DataTestMethod]
[DynamicData(nameof(GetPackagesConfigTemplates), DynamicDataSourceType.Method)]
[Timeout(DefaultTimeout)]
public void InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails(ProjectTemplate projectTemplate)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This test is timing out.

as is NuGet.Tests.Apex.NuGetConsoleTestCase.InstallPackageForPC_PackageSourceMapping_WithCorrectSourceOption_InstallsCorrectPackage

Investigate what makes these tests potentially different from other tests in this file and push a fix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9664654 (with the main timeout fix in edaf988). I updated the two timing-out PMC tests to use explicit NuGet.config source/mapping setup (matching the stable pattern in this file) and added a fast-fail package-seeding assertion for the wrong-mapped-feed case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Never use completely handwritten nuget.config. It pollutes the user's global packages folder with test packages and that's not something we want.

Revert back to using the settings.

await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion, "Thisisfromopensourcerepo1.txt");
await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersion, "Thisisfromprivaterepo1.txt");

CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Follow the same feedback as earlier.

Do not use CommonUtility.CreateConfigurationFile in the new tests.
InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails should be fixed in the same way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 23887cf. I removed CommonUtility.CreateConfigurationFile and switched the affected migrated tests back to SimpleTestPathContext.Settings (AddSource + AddPackageSourceMapping), including InstallPackageForPC_PackageSourceMapping_WithWrongMappedFeed_Fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants