@@ -46,6 +46,11 @@ public abstract class TestRunner
4646
4747 public IEnumerable < string > Output { get ; protected set ; }
4848
49+ protected int RunPackageTest ( FilePath executablePath , string arguments = null , bool redirectOutput = false )
50+ {
51+ return RunPackageTest ( executablePath , new ProcessSettings { Arguments = arguments , RedirectStandardOutput = redirectOutput } ) ;
52+ }
53+
4954 protected int RunUnitTest ( FilePath executablePath , ProcessSettings processSettings )
5055 {
5156 if ( executablePath == null )
@@ -266,29 +271,43 @@ public class NUnit4DotNetRunner : NUnitConsoleRunnerBase
266271/////////////////////////////////////////////////////////////////////////////
267272
268273/// <summary>
269- /// Class that knows how to run an agent directly. (For future use)
274+ /// Class that knows how to find and run an agent directly.
270275/// </summary>
271276public class AgentRunner : TestRunner , IPackageTestRunner
272277{
273- private string _stdExecutable ;
274- private string _x86Executable ;
278+ private DirectoryPath _agentBaseDirectory ;
275279
276- private FilePath _executablePath ;
280+ public AgentRunner ( DirectoryPath agentBaseDirectory )
281+ {
282+ if ( agentBaseDirectory == null )
283+ throw new ArgumentNullException ( "Null argument" , nameof ( agentBaseDirectory ) ) ;
277284
278- public AgentRunner ( string stdExecutable , string x86Executable = null )
279- {
280- _stdExecutable = stdExecutable ;
281- _x86Executable = x86Executable ;
285+ _agentBaseDirectory = agentBaseDirectory ;
282286 }
283287
284288 public int RunPackageTest ( string arguments , bool redirectOutput = false )
285289 {
286- _executablePath = arguments . Contains ( "--x86" )
287- ? _x86Executable
288- : _stdExecutable ;
289-
290- return base . RunPackageTest (
291- _executablePath ,
292- new ProcessSettings { Arguments = arguments . Replace ( "--x86" , string . Empty ) , RedirectStandardOutput = redirectOutput } ) ;
290+ if ( ! SIO . Directory . Exists ( _agentBaseDirectory . ToString ( ) ) )
291+ throw new DirectoryNotFoundException ( $ "Directory not found: { _agentBaseDirectory } ") ;
292+
293+ string runtime = arguments . Contains ( "net462" ) ? "net462" : "net8.0" ;
294+ bool isX86 = arguments . Contains ( "--x86" ) ;
295+ arguments = arguments . Replace ( "--x86" , string . Empty ) ;
296+ DirectoryPath agentDirectory = _agentBaseDirectory . Combine ( runtime ) ;
297+
298+ if ( runtime == "net462" )
299+ {
300+ string agentName = isX86 ? "nunit-agent-net462-x86.exe" : "nunit-agent-net462.exe" ;
301+ FilePath agentPath = agentDirectory . CombineWithFilePath ( agentName ) ;
302+ var settings = new ProcessSettings ( ) { Arguments = arguments , RedirectStandardOutput = redirectOutput } ;
303+ return base . RunPackageTest ( agentPath , settings ) ;
304+ }
305+ else // must be "net8.0"
306+ {
307+ string agentName = "nunit-agent-net80.dll" ;
308+ FilePath agentPath = agentDirectory . CombineWithFilePath ( agentName ) ;
309+ var settings = new ProcessSettings ( ) { Arguments = $ "\" { agentPath } \" { arguments } ", RedirectStandardOutput = redirectOutput } ;
310+ return base . RunPackageTest ( "dotnet" , settings ) ;
311+ }
293312 }
294313}
0 commit comments