using System.Diagnostics; using System.Runtime.InteropServices; using WhiteMagic.Windows; using Xunit; namespace WhiteMagicTest.Windows; public sealed class WindowTests { [Fact] public void GetWindows_returns_at_least_one_top_level_window() { var windows = WindowFactory.GetWindows().ToList(); Assert.NotEmpty(windows); } [Fact] public void GetWindowsByClassName_filters_to_matching_classes() { var all = WindowFactory.GetWindows().ToList(); if (all.Count == 0) return; string firstClass = all[0].ClassName; if (string.IsNullOrEmpty(firstClass)) return; var filtered = WindowFactory.GetWindowsByClassName(firstClass).ToList(); Assert.All(filtered, w => Assert.Equal(firstClass, w.ClassName)); Assert.True(filtered.Count <= all.Count); } [Fact] public void RemoteWindow_can_query_and_manipulate_a_test_window() { IntPtr handle = Process.GetCurrentProcess().MainWindowHandle; if (handle == IntPtr.Zero) { // The xUnit runner may not expose a main window; skip destructive // manipulation but still validate factory enumeration above. return; } var window = new RemoteWindow(handle); Assert.Equal(handle, window.Handle); string text = window.Text; Assert.NotNull(text); string originalTitle = window.Title; Assert.Equal(text, originalTitle); // Move and resize, then restore the original position. bool moved = window.MoveResize(10, 10, 400, 300); Assert.True(moved); bool flashed = window.Flash(); Assert.True(flashed); // Restore a sensible size without asserting exact title restoration; // terminal windows often ignore SetWindowText. bool restored = window.MoveResize(0, 0, 800, 600); Assert.True(restored); } }