using System.IO;
using XFEToolBox.Client.Utilities;
namespace XFEToolBox.Client.Wpf.Test;
public static class IndexingServiceInstallationTests
{
[Test]
public static void IndexingServiceElevatesOnlyItsOwnInstallerWithFixedArguments()
{
var application = Path.Combine(Path.GetTempPath(), "XFEToolBox package with spaces");
var start = IndexingServiceInstallation.CreateStartInfo(application, install: true);
Ensure(start.UseShellExecute && start.Verb == "runas", "独立服务安装程序未显式申请管理员权限。");
Ensure(start.FileName == Path.Combine(application, "IndexingService", "XFEToolBox.Indexing.Service.exe"),
"服务安装入口没有定位到独立的服务发行目录。");
Ensure(start.Arguments == "--install" && !start.FileName.EndsWith("\\XFEToolBox.exe", StringComparison.OrdinalIgnoreCase),
"安装服务错误地提权了主程序或传入任意 SCM 参数。");
var uninstall = IndexingServiceInstallation.CreateStartInfo(application, install: false);
Ensure(uninstall.Arguments == "--uninstall" && uninstall.Verb == "runas", "卸载入口未使用固定参数和独立提权。");
}
[Test]
public static async Task IndexingServiceMissingBundleAndCancellationDoNotLaunchUac()
{
var absent = Path.Combine(Path.GetTempPath(), "xfetoolbox-missing-service-" + Guid.NewGuid().ToString("N"));
var missing = await IndexingServiceInstallation.InstallAsync(absent);
Ensure(!missing.Succeeded && !missing.Cancelled && missing.Message.Contains("普通权限"),
"缺少可选服务发行文件时没有明确回退普通权限搜索。");
using var cancellation = new CancellationTokenSource();
cancellation.Cancel();
var cancelled = await IndexingServiceInstallation.InstallAsync(absent, cancellation.Token);
Ensure(!cancelled.Succeeded && cancelled.Cancelled, "提前取消安装时仍尝试打开管理员授权。");
}
private static void Ensure(bool condition, string message)
{
if (!condition) throw new InvalidOperationException(message);
}
}
using System.IO;
using XFEToolBox.Client.Utilities;
namespace XFEToolBox.Client.Wpf.Test;
public static class IndexingServiceInstallationTests
{
[Test]
public static void IndexingServiceElevatesOnlyItsOwnInstallerWithFixedArguments()
{
var application = Path.Combine(Path.GetTempPath(), "XFEToolBox package with spaces");
var start = IndexingServiceInstallation.CreateStartInfo(application, install: true);
Ensure(start.UseShellExecute && start.Verb == "runas", "独立服务安装程序未显式申请管理员权限。");
Ensure(start.FileName == Path.Combine(application, "IndexingService", "XFEToolBox.Indexing.Service.exe"),
"服务安装入口没有定位到独立的服务发行目录。");
Ensure(start.Arguments == "--install" && !start.FileName.EndsWith("\\XFEToolBox.exe", StringComparison.OrdinalIgnoreCase),
"安装服务错误地提权了主程序或传入任意 SCM 参数。");
var uninstall = IndexingServiceInstallation.CreateStartInfo(application, install: false);
Ensure(uninstall.Arguments == "--uninstall" && uninstall.Verb == "runas", "卸载入口未使用固定参数和独立提权。");
}
[Test]
public static async Task IndexingServiceMissingBundleAndCancellationDoNotLaunchUac()
{
var absent = Path.Combine(Path.GetTempPath(), "xfetoolbox-missing-service-" + Guid.NewGuid().ToString("N"));
var missing = await IndexingServiceInstallation.InstallAsync(absent);
Ensure(!missing.Succeeded && !missing.Cancelled && missing.Message.Contains("普通权限"),
"缺少可选服务发行文件时没有明确回退普通权限搜索。");
using var cancellation = new CancellationTokenSource();
cancellation.Cancel();
var cancelled = await IndexingServiceInstallation.InstallAsync(absent, cancellation.Token);
Ensure(!cancelled.Succeeded && cancelled.Cancelled, "提前取消安装时仍尝试打开管理员授权。");
}
private static void Ensure(bool condition, string message)
{
if (!condition) throw new InvalidOperationException(message);
}
}