Skip to content

Commit

Permalink
commands custom OK
Browse files Browse the repository at this point in the history
  • Loading branch information
zijianhuang committed Jun 8, 2024
1 parent ef40806 commit 6cfb586
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>3.4</Version>
<Version>3.5</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>
Expand Down
43 changes: 30 additions & 13 deletions Fonlow.Testing.ServiceCore/ServiceCommandAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics;

namespace Fonlow.Testing
{
{
/// <summary>
/// For starting and stoping service
/// </summary>
Expand All @@ -13,17 +13,34 @@ public ServiceCommandAgent(ServiceCommand serviceCommand)
this.ServicCommand = serviceCommand;
}

public ServiceCommand ServicCommand { get; private set; }

public ServiceCommand ServicCommand { get; private set; }

/// <summary>
/// Start DotNet Kestrel Web server.
/// </summary>
public void Start()
{
ProcessStartInfo info = new ProcessStartInfo(ServicCommand.CommandPath, ServicCommand.Arguments)
{
UseShellExecute = true,
};
{
ProcessStartInfo info;
var dir = System.IO.Path.GetDirectoryName(ServicCommand.CommandPath);
if (string.IsNullOrEmpty(dir))
{
info = new ProcessStartInfo(ServicCommand.CommandPath, ServicCommand.Arguments)
{
UseShellExecute = true,
};
}
else
{
string command = System.IO.Path.GetFileName(ServicCommand.CommandPath);
string workingDir = System.IO.Path.GetFullPath(dir);
info = new ProcessStartInfo(command, ServicCommand.Arguments)
{
UseShellExecute = true,
WorkingDirectory = workingDir
};

Console.WriteLine($"Working Dir: {workingDir}; Current Dir: {System.IO.Directory.GetCurrentDirectory()}");
}

Console.WriteLine($"Starting {ServicCommand.CommandPath} {ServicCommand.Arguments} ...");
process = Process.Start(info);
Expand All @@ -36,8 +53,8 @@ public void Start()

DateTime timeStart;

Process process;

Process process;

/// <summary>
/// Stop service launched by this agent.
/// </summary>
Expand All @@ -51,9 +68,9 @@ public void Stop()
}

try
{
//sometimes the process exited before the kill. Then the kill may leave a ghost terminal screen. This seems to be the new behavior in Windows 11.
// This typically happens when the Web service was launched manually, then run the test suite which will lauch the same service using this agent class.
{
//sometimes the process exited before the kill. Then the kill may leave a ghost terminal screen. This seems to be the new behavior in Windows 11.
// This typically happens when the Web service was launched manually, then run the test suite which will lauch the same service using this agent class.
if (!process.HasExited)
{
process.Kill(true);
Expand Down

0 comments on commit 6cfb586

Please sign in to comment.