From 448764c4321b469fb6d80678469a519b0de85be0 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Tue, 4 Nov 2025 18:27:05 +1000 Subject: [PATCH] Update TestRunnerService.cs --- .../Features/Testing/TestRunnerService.cs | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/SharpIDE.Application/Features/Testing/TestRunnerService.cs b/src/SharpIDE.Application/Features/Testing/TestRunnerService.cs index 30b6144..398f42a 100644 --- a/src/SharpIDE.Application/Features/Testing/TestRunnerService.cs +++ b/src/SharpIDE.Application/Features/Testing/TestRunnerService.cs @@ -7,22 +7,32 @@ namespace SharpIDE.Application.Features.Testing; public class TestRunnerService { + public async Task> DiscoverTests(SharpIdeSolutionModel solutionModel) + { + var testProjects = solutionModel.AllProjects.Where(p => p.IsMtpTestProject).ToList(); + List allDiscoveredTestNodes = []; + foreach (var testProject in testProjects) + { + using var client = await GetInitialisedClientAsync(testProject); + List testNodeUpdates = []; + var discoveryResponse = await client.DiscoverTestsAsync(Guid.NewGuid(), node => + { + testNodeUpdates.AddRange(node); + return Task.CompletedTask; + }); + await discoveryResponse.WaitCompletionAsync(); + + await client.ExitAsync(); + allDiscoveredTestNodes.AddRange(testNodeUpdates.Select(tn => tn.Node)); + } + + return allDiscoveredTestNodes; + } + // Assumes it has already been built public async Task RunTestsAsync(SharpIdeProjectModel project) { - // get path to executable - var outputDllPath = ProjectEvaluation.GetOutputDllFullPath(project); - var outputExecutablePath = 0 switch - { - _ when OperatingSystem.IsWindows() => outputDllPath!.Replace(".dll", ".exe"), - _ when OperatingSystem.IsLinux() => outputDllPath!.Replace(".dll", ""), - _ when OperatingSystem.IsMacOS() => outputDllPath!.Replace(".dll", ""), - _ => throw new PlatformNotSupportedException("Unsupported OS for running tests.") - }; - - using var client = await TestingPlatformClientFactory.StartAsServerAndConnectToTheClientAsync(outputExecutablePath); - - await client.InitializeAsync(); + using var client = await GetInitialisedClientAsync(project); List testNodeUpdates = []; var discoveryResponse = await client.DiscoverTestsAsync(Guid.NewGuid(), node => { @@ -50,4 +60,20 @@ public class TestRunnerService Console.WriteLine($"Passed: {passedCount}; Skipped: {skippedCount}; Failed: {failedCount};"); await client.ExitAsync(); } + + private async Task GetInitialisedClientAsync(SharpIdeProjectModel project) + { + var outputDllPath = ProjectEvaluation.GetOutputDllFullPath(project); + var outputExecutablePath = 0 switch + { + _ when OperatingSystem.IsWindows() => outputDllPath!.Replace(".dll", ".exe"), + _ when OperatingSystem.IsLinux() => outputDllPath!.Replace(".dll", ""), + _ when OperatingSystem.IsMacOS() => outputDllPath!.Replace(".dll", ""), + _ => throw new PlatformNotSupportedException("Unsupported OS for running tests.") + }; + + var client = await TestingPlatformClientFactory.StartAsServerAndConnectToTheClientAsync(outputExecutablePath); + await client.InitializeAsync(); + return client; + } }