Files
One_click_run_wpf/tests/OneClickRun.Tests/PowerShellLocatorTests.cs
T

36 lines
1.0 KiB
C#

using OneClickRun.Services;
using Xunit;
namespace OneClickRun.Tests;
public class PowerShellLocatorTests
{
[Fact]
public void BuildScriptArgumentsQuotesPathsWithSpaces()
{
Assert.Equal(
"-NoProfile -ExecutionPolicy Bypass -File \"C:\\my scripts\\hello.ps1\"",
PowerShellLocator.BuildScriptArguments(@"C:\my scripts\hello.ps1", null));
}
[Fact]
public void BuildScriptArgumentsAppendsExtraArgs()
{
Assert.Equal(
"-NoProfile -ExecutionPolicy Bypass -File \"D:\\a.ps1\" -Name demo",
PowerShellLocator.BuildScriptArguments(@"D:\a.ps1", "-Name demo"));
}
[Fact]
public void FindLocatesPwshOnThisMachineOrReturnsNull()
{
// 开发机已安装 PowerShell 7.6.5;其他环境返回 null 也不算失败
var path = PowerShellLocator.Find();
if (path != null)
{
Assert.EndsWith("pwsh.exe", path, System.StringComparison.OrdinalIgnoreCase);
Assert.True(System.IO.File.Exists(path));
}
}
}