using Xunit; namespace Recordingtest.Recorder.Tests; public class WindowPointResolverTests { private sealed class FakeSnapshot : IElementSnapshot { public string Tag { get; init; } = ""; public string ClassName => Tag; public string? AutomationId => null; public string? Name => Tag; public bool IsPassword => false; public (double Left, double Top, double Width, double Height) BoundingRectangle => (0, 0, 0, 0); public IElementSnapshot? Parent => null; } private sealed class FakeSource : IWindowPointSource { public int? Pid { get; set; } public IElementSnapshot? Primary { get; set; } public IElementSnapshot? SutScope { get; set; } public int? GetProcessIdAt(int x, int y) => Pid; public IElementSnapshot? GetElementAt(int x, int y) => Primary; public IElementSnapshot? GetElementFromSutScope(int x, int y) => SutScope; } [Fact] public void Resolve_SamePid_ReturnsPrimary() { var primary = new FakeSnapshot { Tag = "primary" }; var sut = new FakeSnapshot { Tag = "sut" }; var src = new FakeSource { Pid = 100, Primary = primary, SutScope = sut }; var r = WindowPointResolver.Resolve(src, 10, 20, sutPid: 100); Assert.Same(primary, r); } [Fact] public void Resolve_DifferentPid_FallsBackToSutScope() { var primary = new FakeSnapshot { Tag = "primary" }; var sut = new FakeSnapshot { Tag = "sut" }; var src = new FakeSource { Pid = 999, Primary = primary, SutScope = sut }; var r = WindowPointResolver.Resolve(src, 10, 20, sutPid: 100); Assert.Same(sut, r); } [Fact] public void Resolve_UnknownPid_ReturnsPrimary() { var primary = new FakeSnapshot { Tag = "primary" }; var src = new FakeSource { Pid = null, Primary = primary, SutScope = null }; var r = WindowPointResolver.Resolve(src, 10, 20, sutPid: 100); Assert.Same(primary, r); } [Fact] public void Resolve_ZeroPid_ReturnsPrimary() { var primary = new FakeSnapshot { Tag = "primary" }; var src = new FakeSource { Pid = 0, Primary = primary, SutScope = null }; var r = WindowPointResolver.Resolve(src, 10, 20, sutPid: 100); Assert.Same(primary, r); } [Fact] public void Resolve_DifferentPid_FallbackNull_ReturnsPrimary() { // Documented semantic: if SUT-scope fallback can't find anything, // keep the primary as a last resort rather than dropping the event. var primary = new FakeSnapshot { Tag = "primary" }; var src = new FakeSource { Pid = 999, Primary = primary, SutScope = null }; var r = WindowPointResolver.Resolve(src, 10, 20, sutPid: 100); Assert.Same(primary, r); } }