Skip to content

Commit 7558037

Browse files
committed
ElectronNET.IntegrationTests: Add platform support attributes
1 parent e4485fd commit 7558037

8 files changed

Lines changed: 104 additions & 50 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace ElectronNET.IntegrationTests.Common
2+
{
3+
using System.Runtime.InteropServices;
4+
5+
[AttributeUsage(AttributeTargets.Method)]
6+
internal sealed class SkipOnWslFactAttribute : FactAttribute
7+
{
8+
private static readonly bool IsOnWsl;
9+
10+
static SkipOnWslFactAttribute()
11+
{
12+
IsOnWsl = DetectWsl();
13+
}
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="SkipOnWslFactAttribute" /> class.
17+
/// </summary>
18+
public SkipOnWslFactAttribute()
19+
{
20+
if (IsOnWsl)
21+
{
22+
this.Skip = "Skipping test on WSL environment.";
23+
}
24+
}
25+
26+
private static bool DetectWsl()
27+
{
28+
try
29+
{
30+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
31+
{
32+
return false;
33+
}
34+
35+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSL_DISTRO_NAME")) ||
36+
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSL_INTEROP")))
37+
{
38+
return true;
39+
}
40+
41+
return false;
42+
}
43+
catch
44+
{
45+
return false;
46+
}
47+
}
48+
}
49+
}

src/ElectronNET.IntegrationTests/Tests/AppTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace ElectronNET.IntegrationTests.Tests
22
{
3-
using System.Runtime.InteropServices;
43
using ElectronNET.API;
54
using ElectronNET.API.Entities;
65
using System;
76
using System.IO;
7+
using System.Runtime.Versioning;
88
using System.Threading.Tasks;
99

1010
[Collection("ElectronCollection")]
@@ -62,7 +62,9 @@ public async Task Can_get_gpu_feature_status()
6262
status.Should().NotBeNull();
6363
}
6464

65-
[Fact(Timeout = 20000)]
65+
[SkippableFact(Timeout = 20000)]
66+
[SupportedOSPlatform("macOS")]
67+
[SupportedOSPlatform("Windows")]
6668
public async Task Can_get_login_item_settings()
6769
{
6870
var settings = await Electron.App.GetLoginItemSettingsAsync();
@@ -78,7 +80,9 @@ public async Task CommandLine_append_and_query_switch()
7880
(await Electron.App.CommandLine.GetSwitchValueAsync(switchName)).Should().Be("value123");
7981
}
8082

81-
[Fact(Timeout = 20000)]
83+
[SkippableFact(Timeout = 20000)]
84+
[SupportedOSPlatform("macOS")]
85+
[SupportedOSPlatform("Windows")]
8286
public async Task Accessibility_support_toggle()
8387
{
8488
Electron.App.SetAccessibilitySupportEnabled(true);
@@ -97,7 +101,9 @@ public async Task UserAgentFallback_roundtrip()
97101
Electron.App.UserAgentFallback = original; // restore
98102
}
99103

100-
[Fact(Timeout = 20000)]
104+
[SkippableFact(Timeout = 20000)]
105+
[SupportedOSPlatform("Linux")]
106+
[SupportedOSPlatform("macOS")]
101107
public async Task BadgeCount_set_and_reset_where_supported()
102108
{
103109
await Electron.App.SetBadgeCountAsync(2);
@@ -123,4 +129,4 @@ public async Task App_gpu_feature_status_has_some_fields()
123129
status.VideoDecode.Should().NotBeNull();
124130
}
125131
}
126-
}
132+
}

src/ElectronNET.IntegrationTests/Tests/BrowserWindowTests.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace ElectronNET.IntegrationTests.Tests
22
{
33
using System.Runtime.InteropServices;
4+
using System.Runtime.Versioning;
45
using ElectronNET.API;
56
using ElectronNET.API.Entities;
7+
using ElectronNET.IntegrationTests.Common;
68

79
[Collection("ElectronCollection")]
810
public class BrowserWindowTests
@@ -42,7 +44,7 @@ public async Task Can_set_progress_bar_and_clear()
4244
await Task.Delay(50);
4345
}
4446

45-
[Fact(Timeout = 20000)]
47+
[SkipOnWslFact(Timeout = 20000)]
4648
public async Task Can_set_and_get_position()
4749
{
4850
this.fx.MainWindow.SetPosition(134, 246);
@@ -91,7 +93,9 @@ public async Task AlwaysOnTop_toggle_and_query()
9193
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
9294
}
9395

94-
[Fact(Timeout = 20000)]
96+
[SkippableFact(Timeout = 20000)]
97+
[SupportedOSPlatform("Linux")]
98+
[SupportedOSPlatform("Windows")]
9599
public async Task MenuBar_auto_hide_and_visibility()
96100
{
97101
this.fx.MainWindow.SetAutoHideMenuBar(true);
@@ -165,7 +169,9 @@ public async Task Progress_bar_and_always_on_top_toggle()
165169
(await win.IsAlwaysOnTopAsync()).Should().BeFalse();
166170
}
167171

168-
[Fact(Timeout = 20000)]
172+
[SkippableFact(Timeout = 20000)]
173+
[SupportedOSPlatform("Linux")]
174+
[SupportedOSPlatform("Windows")]
169175
public async Task Menu_bar_visibility_and_auto_hide()
170176
{
171177
var win = this.fx.MainWindow;
@@ -188,36 +194,22 @@ public async Task Parent_child_relationship_roundtrip()
188194
child.Destroy();
189195
}
190196

191-
[Fact(Timeout = 20000)]
197+
[SkippableFact(Timeout = 20000)]
198+
[SupportedOSPlatform("macOS")]
192199
public async Task Represented_filename_and_edited_flags()
193200
{
194201
var win = this.fx.MainWindow;
195202
var temp = Path.Combine(Path.GetTempPath(), "electronnet_test.txt");
196203
File.WriteAllText(temp, "test");
197204
win.SetRepresentedFilename(temp);
198205
var represented = await win.GetRepresentedFilenameAsync();
199-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
200-
{
201-
represented.Should().Be(temp);
202-
}
203-
else
204-
{
205-
// Non-macOS platforms may not support represented filename; empty is acceptable
206-
represented.Should().BeEmpty();
207-
}
206+
represented.Should().Be(temp);
208207

209208
win.SetDocumentEdited(true);
210209
var edited = await win.IsDocumentEditedAsync();
211-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
212-
{
213-
edited.Should().BeTrue();
214-
}
215-
else
216-
{
217-
edited.Should().BeFalse(); // unsupported on non-mac platforms
218-
}
210+
edited.Should().BeTrue();
219211

220212
win.SetDocumentEdited(false);
221213
}
222214
}
223-
}
215+
}

src/ElectronNET.IntegrationTests/Tests/ClipboardTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace ElectronNET.IntegrationTests.Tests
22
{
3+
using System.Runtime.Versioning;
34
using ElectronNET.API;
45

56
[Collection("ElectronCollection")]
@@ -31,7 +32,9 @@ public async Task Available_formats_contains_text_after_write()
3132
formats.Should().Contain(f => f.Contains("text") || f.Contains("TEXT") || f.Contains("plain"));
3233
}
3334

34-
[Fact(Timeout = 20000)]
35+
[SkippableFact(Timeout = 20000)]
36+
[SupportedOSPlatform("macOS")]
37+
[SupportedOSPlatform("Windows")]
3538
public async Task Bookmark_write_and_read()
3639
{
3740
var url = "https://electron-test.com";
@@ -40,4 +43,4 @@ public async Task Bookmark_write_and_read()
4043
bookmark.Url.Should().Be(url);
4144
}
4245
}
43-
}
46+
}

src/ElectronNET.IntegrationTests/Tests/NativeThemeTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace ElectronNET.IntegrationTests.Tests
22
{
3+
using System.Runtime.Versioning;
34
using ElectronNET.API;
45
using ElectronNET.API.Entities;
56

@@ -46,18 +47,22 @@ public async Task Updated_event_fires_on_change()
4647
fired.Should().BeTrue();
4748
}
4849

49-
[Fact(Timeout = 20000)]
50+
[SkippableFact(Timeout = 20000)]
51+
[SupportedOSPlatform("macOS")]
52+
[SupportedOSPlatform("Windows")]
5053
public async Task Should_use_high_contrast_colors_check()
5154
{
5255
var metrics = await Electron.NativeTheme.ShouldUseHighContrastColorsAsync();
5356
metrics.Should().Be(false);
5457
}
5558

56-
[Fact(Timeout = 20000)]
59+
[SkippableFact(Timeout = 20000)]
60+
[SupportedOSPlatform("macOS")]
61+
[SupportedOSPlatform("Windows")]
5762
public async Task Should_use_inverted_colors_check()
5863
{
5964
var metrics = await Electron.NativeTheme.ShouldUseInvertedColorSchemeAsync();
6065
metrics.Should().Be(false);
6166
}
6267
}
63-
}
68+
}

src/ElectronNET.IntegrationTests/Tests/ScreenTests.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using ElectronNET.API.Entities;
2-
31
namespace ElectronNET.IntegrationTests.Tests
42
{
3+
using System.Runtime.Versioning;
54
using ElectronNET.API;
5+
using ElectronNET.API.Entities;
6+
using ElectronNET.IntegrationTests.Common;
67

78
[Collection("ElectronCollection")]
89
public class ScreenTests
@@ -15,15 +16,15 @@ public ScreenTests(ElectronFixture fx)
1516
this.fx = fx;
1617
}
1718

18-
[Fact(Timeout = 20000)]
19+
[SkipOnWslFact(Timeout = 20000)]
1920
public async Task Primary_display_has_positive_dimensions()
2021
{
2122
var display = await Electron.Screen.GetPrimaryDisplayAsync();
2223
display.Size.Width.Should().BeGreaterThan(0);
2324
display.Size.Height.Should().BeGreaterThan(0);
2425
}
2526

26-
[Fact(Timeout = 20000)]
27+
[SkipOnWslFact(Timeout = 20000)]
2728
public async Task GetAllDisplays_returns_at_least_one()
2829
{
2930
var displays = await Electron.Screen.GetAllDisplaysAsync();
@@ -40,7 +41,8 @@ public async Task GetCursorScreenPoint_check()
4041
point.Y.Should().BeGreaterThanOrEqualTo(0);
4142
}
4243

43-
[Fact(Timeout = 20000)]
44+
[SkippableFact(Timeout = 20000)]
45+
[SupportedOSPlatform("macOS")]
4446
public async Task GetMenuBarWorkArea_check()
4547
{
4648
var area = await Electron.Screen.GetMenuBarWorkAreaAsync();
@@ -51,7 +53,7 @@ public async Task GetMenuBarWorkArea_check()
5153
area.Width.Should().BeGreaterThan(0);
5254
}
5355

54-
[Fact(Timeout = 20000)]
56+
[SkipOnWslFact(Timeout = 20000)]
5557
public async Task GetDisplayNearestPoint_check()
5658
{
5759
var point = new Point
@@ -65,7 +67,7 @@ public async Task GetDisplayNearestPoint_check()
6567
display.Size.Height.Should().BeGreaterThan(0);
6668
}
6769

68-
[Fact(Timeout = 20000)]
70+
[SkipOnWslFact(Timeout = 20000)]
6971
public async Task GetDisplayMatching_check()
7072
{
7173
var rectangle = new Rectangle
@@ -81,4 +83,4 @@ public async Task GetDisplayMatching_check()
8183
display.Size.Height.Should().BeGreaterThan(0);
8284
}
8385
}
84-
}
86+
}

src/ElectronNET.IntegrationTests/Tests/ShellTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ElectronNET.IntegrationTests.Tests
55
[Collection("ElectronCollection")]
66
public class ShellTests
77
{
8-
[Fact(Timeout = 20000)]
8+
[Fact(Skip = "This can keep the test process hanging until the e-mail window is closed")]
99
public async Task OpenExternal_invalid_scheme_returns_error_or_empty()
1010
{
1111
var error = await Electron.Shell.OpenExternalAsync("mailto:test@example.com");

src/ElectronNET.IntegrationTests/Tests/ThumbarButtonTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace ElectronNET.IntegrationTests.Tests
22
{
3-
using System.Runtime.InteropServices;
3+
using System.Runtime.Versioning;
44
using ElectronNET.API.Entities;
55

66
[Collection("ElectronCollection")]
@@ -13,22 +13,19 @@ public ThumbarButtonTests(ElectronFixture fx)
1313
this.fx = fx;
1414
}
1515

16-
[Fact(Timeout = 20000)]
16+
[SkippableFact(Timeout = 20000)]
17+
[SupportedOSPlatform("Windows")]
1718
public async Task SetThumbarButtons_returns_success()
1819
{
1920
var btn = new ThumbarButton("icon.png") { Tooltip = "Test" };
2021
var success = await this.fx.MainWindow.SetThumbarButtonsAsync(new[] { btn });
2122
success.Should().BeTrue();
2223
}
2324

24-
[Fact(Timeout = 20000)]
25+
[SkippableFact(Timeout = 20000)]
26+
[SupportedOSPlatform("Windows")]
2527
public async Task Thumbar_button_click_invokes_callback()
2628
{
27-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
28-
{
29-
return; // only meaningful on Windows taskbar
30-
}
31-
3229
var icon = Path.Combine(Directory.GetCurrentDirectory(), "ElectronNET.WebApp", "wwwroot", "icon.png");
3330
if (!File.Exists(icon))
3431
{
@@ -41,4 +38,4 @@ public async Task Thumbar_button_click_invokes_callback()
4138
ok.Should().BeTrue();
4239
}
4340
}
44-
}
41+
}

0 commit comments

Comments
 (0)