ElectronNET.IntegrationTests: Add platform support attributes

This commit is contained in:
softworkz
2025-11-16 00:29:48 +01:00
parent e4485fd483
commit 7558037b91
8 changed files with 104 additions and 50 deletions

View File

@@ -0,0 +1,49 @@
namespace ElectronNET.IntegrationTests.Common
{
using System.Runtime.InteropServices;
[AttributeUsage(AttributeTargets.Method)]
internal sealed class SkipOnWslFactAttribute : FactAttribute
{
private static readonly bool IsOnWsl;
static SkipOnWslFactAttribute()
{
IsOnWsl = DetectWsl();
}
/// <summary>
/// Initializes a new instance of the <see cref="SkipOnWslFactAttribute" /> class.
/// </summary>
public SkipOnWslFactAttribute()
{
if (IsOnWsl)
{
this.Skip = "Skipping test on WSL environment.";
}
}
private static bool DetectWsl()
{
try
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return false;
}
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSL_DISTRO_NAME")) ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSL_INTEROP")))
{
return true;
}
return false;
}
catch
{
return false;
}
}
}
}

View File

@@ -1,10 +1,10 @@
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.InteropServices;
using ElectronNET.API;
using ElectronNET.API.Entities;
using System;
using System.IO;
using System.Runtime.Versioning;
using System.Threading.Tasks;
[Collection("ElectronCollection")]
@@ -62,7 +62,9 @@ namespace ElectronNET.IntegrationTests.Tests
status.Should().NotBeNull();
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task Can_get_login_item_settings()
{
var settings = await Electron.App.GetLoginItemSettingsAsync();
@@ -78,7 +80,9 @@ namespace ElectronNET.IntegrationTests.Tests
(await Electron.App.CommandLine.GetSwitchValueAsync(switchName)).Should().Be("value123");
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task Accessibility_support_toggle()
{
Electron.App.SetAccessibilitySupportEnabled(true);
@@ -97,7 +101,9 @@ namespace ElectronNET.IntegrationTests.Tests
Electron.App.UserAgentFallback = original; // restore
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
public async Task BadgeCount_set_and_reset_where_supported()
{
await Electron.App.SetBadgeCountAsync(2);
@@ -123,4 +129,4 @@ namespace ElectronNET.IntegrationTests.Tests
status.VideoDecode.Should().NotBeNull();
}
}
}
}

View File

@@ -1,8 +1,10 @@
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ElectronNET.API;
using ElectronNET.API.Entities;
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class BrowserWindowTests
@@ -42,7 +44,7 @@ namespace ElectronNET.IntegrationTests.Tests
await Task.Delay(50);
}
[Fact(Timeout = 20000)]
[SkipOnWslFact(Timeout = 20000)]
public async Task Can_set_and_get_position()
{
this.fx.MainWindow.SetPosition(134, 246);
@@ -91,7 +93,9 @@ namespace ElectronNET.IntegrationTests.Tests
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("Windows")]
public async Task MenuBar_auto_hide_and_visibility()
{
this.fx.MainWindow.SetAutoHideMenuBar(true);
@@ -165,7 +169,9 @@ namespace ElectronNET.IntegrationTests.Tests
(await win.IsAlwaysOnTopAsync()).Should().BeFalse();
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("Windows")]
public async Task Menu_bar_visibility_and_auto_hide()
{
var win = this.fx.MainWindow;
@@ -188,7 +194,8 @@ namespace ElectronNET.IntegrationTests.Tests
child.Destroy();
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
public async Task Represented_filename_and_edited_flags()
{
var win = this.fx.MainWindow;
@@ -196,28 +203,13 @@ namespace ElectronNET.IntegrationTests.Tests
File.WriteAllText(temp, "test");
win.SetRepresentedFilename(temp);
var represented = await win.GetRepresentedFilenameAsync();
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
represented.Should().Be(temp);
}
else
{
// Non-macOS platforms may not support represented filename; empty is acceptable
represented.Should().BeEmpty();
}
represented.Should().Be(temp);
win.SetDocumentEdited(true);
var edited = await win.IsDocumentEditedAsync();
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
edited.Should().BeTrue();
}
else
{
edited.Should().BeFalse(); // unsupported on non-mac platforms
}
edited.Should().BeTrue();
win.SetDocumentEdited(false);
}
}
}
}

View File

@@ -1,5 +1,6 @@
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.Versioning;
using ElectronNET.API;
[Collection("ElectronCollection")]
@@ -31,7 +32,9 @@ namespace ElectronNET.IntegrationTests.Tests
formats.Should().Contain(f => f.Contains("text") || f.Contains("TEXT") || f.Contains("plain"));
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task Bookmark_write_and_read()
{
var url = "https://electron-test.com";
@@ -40,4 +43,4 @@ namespace ElectronNET.IntegrationTests.Tests
bookmark.Url.Should().Be(url);
}
}
}
}

View File

@@ -1,5 +1,6 @@
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.Versioning;
using ElectronNET.API;
using ElectronNET.API.Entities;
@@ -46,18 +47,22 @@ namespace ElectronNET.IntegrationTests.Tests
fired.Should().BeTrue();
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task Should_use_high_contrast_colors_check()
{
var metrics = await Electron.NativeTheme.ShouldUseHighContrastColorsAsync();
metrics.Should().Be(false);
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
public async Task Should_use_inverted_colors_check()
{
var metrics = await Electron.NativeTheme.ShouldUseInvertedColorSchemeAsync();
metrics.Should().Be(false);
}
}
}
}

View File

@@ -1,8 +1,9 @@
using ElectronNET.API.Entities;
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.Versioning;
using ElectronNET.API;
using ElectronNET.API.Entities;
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class ScreenTests
@@ -15,7 +16,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact(Timeout = 20000)]
[SkipOnWslFact(Timeout = 20000)]
public async Task Primary_display_has_positive_dimensions()
{
var display = await Electron.Screen.GetPrimaryDisplayAsync();
@@ -23,7 +24,7 @@ namespace ElectronNET.IntegrationTests.Tests
display.Size.Height.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
[SkipOnWslFact(Timeout = 20000)]
public async Task GetAllDisplays_returns_at_least_one()
{
var displays = await Electron.Screen.GetAllDisplaysAsync();
@@ -40,7 +41,8 @@ namespace ElectronNET.IntegrationTests.Tests
point.Y.Should().BeGreaterThanOrEqualTo(0);
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("macOS")]
public async Task GetMenuBarWorkArea_check()
{
var area = await Electron.Screen.GetMenuBarWorkAreaAsync();
@@ -51,7 +53,7 @@ namespace ElectronNET.IntegrationTests.Tests
area.Width.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
[SkipOnWslFact(Timeout = 20000)]
public async Task GetDisplayNearestPoint_check()
{
var point = new Point
@@ -65,7 +67,7 @@ namespace ElectronNET.IntegrationTests.Tests
display.Size.Height.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
[SkipOnWslFact(Timeout = 20000)]
public async Task GetDisplayMatching_check()
{
var rectangle = new Rectangle
@@ -81,4 +83,4 @@ namespace ElectronNET.IntegrationTests.Tests
display.Size.Height.Should().BeGreaterThan(0);
}
}
}
}

View File

@@ -5,7 +5,7 @@ namespace ElectronNET.IntegrationTests.Tests
[Collection("ElectronCollection")]
public class ShellTests
{
[Fact(Timeout = 20000)]
[Fact(Skip = "This can keep the test process hanging until the e-mail window is closed")]
public async Task OpenExternal_invalid_scheme_returns_error_or_empty()
{
var error = await Electron.Shell.OpenExternalAsync("mailto:test@example.com");

View File

@@ -1,6 +1,6 @@
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ElectronNET.API.Entities;
[Collection("ElectronCollection")]
@@ -13,7 +13,8 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("Windows")]
public async Task SetThumbarButtons_returns_success()
{
var btn = new ThumbarButton("icon.png") { Tooltip = "Test" };
@@ -21,14 +22,10 @@ namespace ElectronNET.IntegrationTests.Tests
success.Should().BeTrue();
}
[Fact(Timeout = 20000)]
[SkippableFact(Timeout = 20000)]
[SupportedOSPlatform("Windows")]
public async Task Thumbar_button_click_invokes_callback()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return; // only meaningful on Windows taskbar
}
var icon = Path.Combine(Directory.GetCurrentDirectory(), "ElectronNET.WebApp", "wwwroot", "icon.png");
if (!File.Exists(icon))
{
@@ -41,4 +38,4 @@ namespace ElectronNET.IntegrationTests.Tests
ok.Should().BeTrue();
}
}
}
}