fix(launcher): close LA4 review findings
This commit is contained in:
parent
d0a9c65d85
commit
10a712d66b
19 changed files with 1631 additions and 134 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System.Diagnostics;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AcDream.Launcher.Tests;
|
||||
|
|
@ -56,6 +57,95 @@ public sealed class LauncherProjectBoundaryTests
|
|||
Assert.Contains("tests/AcDream.Launcher.Tests/AcDream.Launcher.Tests.csproj", paths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinuxPublishEvaluatesAsSelfContainedSingleFile()
|
||||
{
|
||||
string root = FindRepositoryRoot();
|
||||
string projectPath = Path.Combine(
|
||||
root,
|
||||
"src",
|
||||
"AcDream.Launcher",
|
||||
"AcDream.Launcher.csproj");
|
||||
|
||||
Assert.Equal("true", EvaluateProperty(projectPath, "SelfContained"));
|
||||
Assert.Equal("true", EvaluateProperty(projectPath, "PublishSingleFile"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModalMarkupAndCodeBehindCarryKeyboardFocusAndAccessibilityGuards()
|
||||
{
|
||||
string root = FindRepositoryRoot();
|
||||
string markup = File.ReadAllText(Path.Combine(
|
||||
root,
|
||||
"src",
|
||||
"AcDream.Launcher",
|
||||
"MainWindow.axaml"));
|
||||
string codeBehind = File.ReadAllText(Path.Combine(
|
||||
root,
|
||||
"src",
|
||||
"AcDream.Launcher",
|
||||
"MainWindow.axaml.cs"));
|
||||
|
||||
Assert.Equal(3, Count(markup, "KeyboardNavigation.TabNavigation=\"Cycle\""));
|
||||
Assert.Equal(3, Count(markup, "KeyDown=\"OnModalKeyDown\""));
|
||||
Assert.True(Count(markup, "AutomationProperties.Name=") >= 13);
|
||||
Assert.True(Count(markup, "IsDefault=\"True\"") >= 3);
|
||||
Assert.True(Count(markup, "IsCancel=\"True\"") >= 3);
|
||||
Assert.Contains("ServerNameTextBox", markup, StringComparison.Ordinal);
|
||||
Assert.Contains("AccountNameTextBox", markup, StringComparison.Ordinal);
|
||||
Assert.Contains("CharacterNameTextBox", markup, StringComparison.Ordinal);
|
||||
Assert.Contains("FocusActiveModal", codeBehind, StringComparison.Ordinal);
|
||||
Assert.Contains("_focusBeforeModal", codeBehind, StringComparison.Ordinal);
|
||||
Assert.Contains("Key.Escape", codeBehind, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortabilityWorkflowBuildsTestsPublishesAndExecutesTheLauncher()
|
||||
{
|
||||
string workflow = File.ReadAllText(Path.Combine(
|
||||
FindRepositoryRoot(),
|
||||
".github",
|
||||
"workflows",
|
||||
"headless-portability.yml"));
|
||||
|
||||
Assert.Contains("src/AcDream.Launcher/**", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("tests/AcDream.Launcher.Tests/**", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("portable-launcher:", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("tests/AcDream.Launcher.Tests/AcDream.Launcher.Tests.csproj", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("-r linux-x64", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("-getProperty:SelfContained", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("DOTNET_ROOT", workflow, StringComparison.Ordinal);
|
||||
Assert.Contains("--verify-publish", workflow, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static string EvaluateProperty(string projectPath, string property)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo("dotnet")
|
||||
{
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
};
|
||||
startInfo.ArgumentList.Add("msbuild");
|
||||
startInfo.ArgumentList.Add(projectPath);
|
||||
startInfo.ArgumentList.Add("-nologo");
|
||||
startInfo.ArgumentList.Add("-property:RuntimeIdentifier=linux-x64");
|
||||
startInfo.ArgumentList.Add($"-getProperty:{property}");
|
||||
|
||||
using Process process = Process.Start(startInfo)
|
||||
?? throw new InvalidOperationException("Could not start dotnet msbuild.");
|
||||
string output = process.StandardOutput.ReadToEnd();
|
||||
string error = process.StandardError.ReadToEnd();
|
||||
Assert.True(process.WaitForExit(30_000), "dotnet msbuild did not exit.");
|
||||
Assert.True(
|
||||
process.ExitCode == 0,
|
||||
$"dotnet msbuild exited {process.ExitCode}: {error}");
|
||||
return output.Trim();
|
||||
}
|
||||
|
||||
private static int Count(string text, string value) =>
|
||||
text.Split(value, StringSplitOptions.None).Length - 1;
|
||||
|
||||
private static string FindRepositoryRoot()
|
||||
{
|
||||
foreach (string start in new[] { AppContext.BaseDirectory, Environment.CurrentDirectory })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue