Skip to content

Commit 81bee90

Browse files
Copilotnkolev92
andcommitted
Migrate NetCore E2E tests from PS to Apex
Migrate Test-NetCoreProjectSystemCacheUpdateEvent and Test-NetCoreVSandMSBuildNoOp from NetCoreProjectTest.ps1 to NetCoreProjectTestCase.cs Apex tests. Remove Test-NetCoreConsoleAppClean and Test-NetCoreConsoleAppRebuildDoesNotDeleteCacheFile from PS (already covered by Daily Apex VerifyCacheFileInsideObjFolder). Three remaining PS tests (TargetFrameworks, MultipleTargetFrameworks, Tools NoOp) are left as-is since they use project templates without Apex equivalents. Agent-Logs-Url: https://github.com/NuGet/NuGet.Client/sessions/9ef1f0b8-2661-453f-92d3-d71db5dd4ac2 Co-authored-by: nkolev92 <[email protected]>
1 parent 779eff1 commit 81bee90

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Threading.Tasks;
45
using Microsoft.Test.Apex.VisualStudio.Solution;
@@ -233,6 +234,79 @@ public async Task WithSourceMappingEnabled_InstallPackageFromPMUIAndNoSourcesFou
233234
}
234235
}
235236

237+
// Migrated from Test-NetCoreProjectSystemCacheUpdateEvent in NetCoreProjectTest.ps1
238+
[TestMethod]
239+
[Timeout(DefaultTimeout)]
240+
public async Task InstallPackageFromPMC_TriggersNuGetCacheUpdatedEventAsync()
241+
{
242+
// Arrange
243+
using var testContext = new ApexTestContext(VisualStudio, ProjectTemplate.NetCoreConsoleApp, Logger, addNetStandardFeeds: true);
244+
245+
var packageName = "TestPackage";
246+
var packageVersion = "1.0.0";
247+
await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion);
248+
249+
testContext.SolutionService.Build();
250+
testContext.NuGetApexTestService.WaitForAutoRestore();
251+
252+
var nugetConsole = GetConsole(testContext.Project);
253+
254+
// Register for the ISolutionManager.AfterNuGetCacheUpdated event via PMC PowerShell session
255+
nugetConsole.Execute("Get-Event | Remove-Event");
256+
nugetConsole.Execute("$componentModel = Get-VSComponentModel");
257+
nugetConsole.Execute("$solutionManager = $componentModel.GetService([NuGet.PackageManagement.ISolutionManager])");
258+
nugetConsole.Execute("Register-ObjectEvent -InputObject $solutionManager -EventName AfterNuGetCacheUpdated -SourceIdentifier SolutionManagerCacheUpdated");
259+
260+
// Act
261+
nugetConsole.InstallPackageFromPMC(packageName, packageVersion);
262+
263+
// Assert - verify the cache update event was raised
264+
nugetConsole.Execute("$cacheEvent = Wait-Event -SourceIdentifier SolutionManagerCacheUpdated -TimeoutSec 10");
265+
nugetConsole.Execute("Unregister-Event -SourceIdentifier SolutionManagerCacheUpdated");
266+
nugetConsole.Execute("if ($cacheEvent) { Write-Host 'CACHE_EVENT_RECEIVED' } else { Write-Host 'CACHE_EVENT_NOT_RECEIVED' }");
267+
268+
Assert.IsTrue(
269+
nugetConsole.IsMessageFoundInPMC("CACHE_EVENT_RECEIVED"),
270+
$"Cache update event should have been raised after package install. Actual PMC output: {nugetConsole.GetText()}");
271+
}
272+
273+
// Migrated from Test-NetCoreVSandMSBuildNoOp in NetCoreProjectTest.ps1
274+
[Ignore("https://github.com/NuGet/Home/issues/13003")]
275+
[TestMethod]
276+
[Timeout(DefaultTimeout)]
277+
public void NetCoreVSandMSBuildRestoreIsNoOp()
278+
{
279+
// Arrange
280+
using var testContext = new ApexTestContext(VisualStudio, ProjectTemplate.NetCoreConsoleApp, Logger, addNetStandardFeeds: true);
281+
282+
testContext.SolutionService.Build();
283+
testContext.NuGetApexTestService.WaitForAutoRestore();
284+
285+
var cacheFilePath = CommonUtility.GetCacheFilePath(testContext.Project.FullPath);
286+
CommonUtility.WaitForFileExists(cacheFilePath);
287+
288+
var vsRestoreTimestamp = File.GetLastWriteTime(cacheFilePath.FullName).Ticks;
289+
290+
// Act - run MSBuild restore externally
291+
using var process = new Process();
292+
process.StartInfo.FileName = "dotnet";
293+
process.StartInfo.Arguments = $"msbuild /t:restore \"{testContext.Project.FullPath}\"";
294+
process.StartInfo.UseShellExecute = false;
295+
process.StartInfo.RedirectStandardOutput = true;
296+
process.StartInfo.RedirectStandardError = true;
297+
process.Start();
298+
string standardError = process.StandardError.ReadToEnd();
299+
process.WaitForExit();
300+
301+
Assert.AreEqual(0, process.ExitCode, $"MSBuild restore failed: {standardError}");
302+
303+
var msbuildRestoreTimestamp = File.GetLastWriteTime(cacheFilePath.FullName).Ticks;
304+
305+
// Assert - MSBuild restore should be a no-op, cache file timestamp should not change
306+
Assert.AreEqual(vsRestoreTimestamp, msbuildRestoreTimestamp,
307+
"MSBuild restore should be a no-op after VS restore - cache file timestamp should not change.");
308+
}
309+
236310
// There is a bug with VS or Apex where NetCoreConsoleApp and NetCoreClassLib create netcore 2.1 projects that are not supported by the sdk
237311
// Commenting out any NetCoreConsoleApp or NetCoreClassLib template and swapping it for NetStandardClassLib as both are package ref.
238312

0 commit comments

Comments
 (0)