using System.Diagnostics; namespace VoiceCat.Tests; public class PublishServerScriptTests { [Fact] public async Task DefaultPublishTargetsWindowsAndLinuxWhileRuntimeCanSelectOne() { string script = Path.Combine(FindRoot(), "scripts", "publish-server.ps1"); string allTargets = await RunWhatIf(script); Assert.Contains("win-x64", allTargets); Assert.Contains("linux-x64", allTargets); string linuxOnly = await RunWhatIf(script, "-Runtime", "linux-x64"); Assert.Contains("linux-x64", linuxOnly); Assert.DoesNotContain("win-x64", linuxOnly); } private static async Task RunWhatIf(string script, params string[] arguments) { string powerShell = OperatingSystem.IsWindows() ? "powershell.exe" : "pwsh"; var start = new ProcessStartInfo(powerShell) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, }; foreach (string argument in new[] { "-NoProfile", "-NonInteractive", "-File", script, "-WhatIf" }.Concat(arguments)) start.ArgumentList.Add(argument); using Process process = Process.Start(start) ?? throw new InvalidOperationException("Could not start PowerShell."); Task stdout = process.StandardOutput.ReadToEndAsync(); Task stderr = process.StandardError.ReadToEndAsync(); await process.WaitForExitAsync(); string output = await stdout + await stderr; Assert.True(process.ExitCode == 0, output); return output; } private static string FindRoot() { DirectoryInfo? directory = new(AppContext.BaseDirectory); while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "VoiceCat.slnx"))) directory = directory.Parent; return directory?.FullName ?? throw new DirectoryNotFoundException("Repository root not found."); } }