Skip to content

Commit 95e02e2

Browse files
committed
Introduce common base class for tests
1 parent 153625b commit 95e02e2

22 files changed

+184
-179
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace ElectronNET.IntegrationTests.Common
2+
{
3+
using ElectronNET.API;
4+
using ElectronNET.API.Entities;
5+
6+
// Base class for integration tests providing shared access to MainWindow and OS platform constants
7+
public abstract class IntegrationTestBase
8+
{
9+
protected IntegrationTestBase(ElectronFixture fixture)
10+
{
11+
Fixture = fixture;
12+
MainWindow = fixture.MainWindow;
13+
}
14+
15+
protected ElectronFixture Fixture { get; }
16+
protected BrowserWindow MainWindow { get; }
17+
18+
// Constants for SupportedOSPlatform attributes
19+
public const string Windows = "Windows";
20+
public const string MacOS = "macOS";
21+
public const string Linux = "Linux";
22+
}
23+
}

src/ElectronNET.IntegrationTests/Tests/AppTests.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ namespace ElectronNET.IntegrationTests.Tests
99
using ElectronNET.IntegrationTests.Common;
1010

1111
[Collection("ElectronCollection")]
12-
public class AppTests
12+
public class AppTests : IntegrationTestBase
1313
{
14-
// ReSharper disable once NotAccessedField.Local
15-
private readonly ElectronFixture fx;
16-
17-
public AppTests(ElectronFixture fx)
14+
public AppTests(ElectronFixture fx) : base(fx)
1815
{
19-
this.fx = fx;
2016
}
2117

2218
[IntegrationFact]
@@ -64,8 +60,8 @@ public async Task Can_get_gpu_feature_status()
6460
}
6561

6662
[IntegrationFact]
67-
[SupportedOSPlatform("macOS")]
68-
[SupportedOSPlatform("Windows")]
63+
[SupportedOSPlatform(MacOS)]
64+
[SupportedOSPlatform(Windows)]
6965
public async Task Can_get_login_item_settings()
7066
{
7167
var settings = await Electron.App.GetLoginItemSettingsAsync();
@@ -82,8 +78,8 @@ public async Task CommandLine_append_and_query_switch()
8278
}
8379

8480
[IntegrationFact]
85-
[SupportedOSPlatform("macOS")]
86-
[SupportedOSPlatform("Windows")]
81+
[SupportedOSPlatform(MacOS)]
82+
[SupportedOSPlatform(Windows)]
8783
public async Task Accessibility_support_toggle()
8884
{
8985
Electron.App.SetAccessibilitySupportEnabled(true);
@@ -103,8 +99,8 @@ public async Task UserAgentFallback_roundtrip()
10399
}
104100

105101
[IntegrationFact]
106-
[SupportedOSPlatform("Linux")]
107-
[SupportedOSPlatform("macOS")]
102+
[SupportedOSPlatform(Linux)]
103+
[SupportedOSPlatform(MacOS)]
108104
public async Task BadgeCount_set_and_reset_where_supported()
109105
{
110106
await Electron.App.SetBadgeCountAsync(2);

src/ElectronNET.IntegrationTests/Tests/AutoUpdaterTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
using ElectronNET.IntegrationTests.Common;
77

88
[Collection("ElectronCollection")]
9-
public class AutoUpdaterTests
9+
public class AutoUpdaterTests : IntegrationTestBase
1010
{
11-
private readonly ElectronFixture fx;
12-
13-
public AutoUpdaterTests(ElectronFixture fx)
11+
public AutoUpdaterTests(ElectronFixture fx) : base(fx)
1412
{
15-
this.fx = fx;
1613
}
1714

1815
[IntegrationFact]

src/ElectronNET.IntegrationTests/Tests/BrowserViewTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ namespace ElectronNET.IntegrationTests.Tests
55
using ElectronNET.IntegrationTests.Common;
66

77
[Collection("ElectronCollection")]
8-
public class BrowserViewTests
8+
public class BrowserViewTests : IntegrationTestBase
99
{
10-
private readonly ElectronFixture fx;
11-
12-
public BrowserViewTests(ElectronFixture fx)
10+
public BrowserViewTests(ElectronFixture fx) : base(fx)
1311
{
14-
this.fx = fx;
1512
}
1613

1714
[IntegrationFact]
1815
public async Task Create_browser_view_and_adjust_bounds()
1916
{
2017
var view = await Electron.WindowManager.CreateBrowserViewAsync(new BrowserViewConstructorOptions());
21-
this.fx.MainWindow.SetBrowserView(view);
18+
this.MainWindow.SetBrowserView(view);
2219
view.Bounds = new Rectangle { X = 0, Y = 0, Width = 300, Height = 200 };
2320
// Access bounds again (synchronous property fetch)
2421
var current = view.Bounds;

src/ElectronNET.IntegrationTests/Tests/BrowserWindowTests.cs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,28 @@ namespace ElectronNET.IntegrationTests.Tests
77
using ElectronNET.IntegrationTests.Common;
88

99
[Collection("ElectronCollection")]
10-
public class BrowserWindowTests
10+
public class BrowserWindowTests : IntegrationTestBase
1111
{
12-
private readonly ElectronFixture fx;
13-
14-
public BrowserWindowTests(ElectronFixture fx)
12+
public BrowserWindowTests(ElectronFixture fx) : base(fx)
1513
{
16-
this.fx = fx;
1714
}
1815

1916
[IntegrationFact]
2017
public async Task Can_set_and_get_title()
2118
{
2219
const string title = "Integration Test Title";
23-
this.fx.MainWindow.SetTitle(title);
20+
this.MainWindow.SetTitle(title);
2421
await Task.Delay(500.ms());
25-
var roundTrip = await this.fx.MainWindow.GetTitleAsync();
22+
var roundTrip = await this.MainWindow.GetTitleAsync();
2623
roundTrip.Should().Be(title);
2724
}
2825

2926
[IntegrationFact]
3027
public async Task Can_resize_and_get_size()
3128
{
32-
this.fx.MainWindow.SetSize(643, 482);
29+
this.MainWindow.SetSize(643, 482);
3330
await Task.Delay(500.ms());
34-
var size = await this.fx.MainWindow.GetSizeAsync();
31+
var size = await this.MainWindow.GetSizeAsync();
3532
size.Should().HaveCount(2);
3633
size[0].Should().Be(643);
3734
size[1].Should().Be(482);
@@ -40,28 +37,28 @@ public async Task Can_resize_and_get_size()
4037
[IntegrationFact]
4138
public async Task Can_set_progress_bar_and_clear()
4239
{
43-
this.fx.MainWindow.SetProgressBar(0.5);
40+
this.MainWindow.SetProgressBar(0.5);
4441
// No direct getter; rely on absence of error. Try changing again.
45-
this.fx.MainWindow.SetProgressBar(-1); // clears
42+
this.MainWindow.SetProgressBar(-1); // clears
4643
await Task.Delay(50.ms());
4744
}
4845

4946
[IntegrationFact(SkipOnWsl = true)]
5047
public async Task Can_set_and_get_position()
5148
{
52-
this.fx.MainWindow.SetPosition(134, 246);
49+
this.MainWindow.SetPosition(134, 246);
5350
await Task.Delay(500.ms());
54-
var pos = await this.fx.MainWindow.GetPositionAsync();
51+
var pos = await this.MainWindow.GetPositionAsync();
5552
pos.Should().BeEquivalentTo([134, 246]);
5653
}
5754

5855
[IntegrationFact]
5956
public async Task Can_set_and_get_bounds()
6057
{
6158
var bounds = new Rectangle { X = 10, Y = 20, Width = 400, Height = 300 };
62-
this.fx.MainWindow.SetBounds(bounds);
59+
this.MainWindow.SetBounds(bounds);
6360
await Task.Delay(500.ms());
64-
var round = await this.fx.MainWindow.GetBoundsAsync();
61+
var round = await this.MainWindow.GetBoundsAsync();
6562

6663
round.Should().BeEquivalentTo(bounds);
6764
round.Width.Should().Be(400);
@@ -72,9 +69,9 @@ public async Task Can_set_and_get_bounds()
7269
public async Task Can_set_and_get_content_bounds()
7370
{
7471
var bounds = new Rectangle { X = 0, Y = 0, Width = 300, Height = 200 };
75-
this.fx.MainWindow.SetContentBounds(bounds);
72+
this.MainWindow.SetContentBounds(bounds);
7673
await Task.Delay(500.ms());
77-
var round = await this.fx.MainWindow.GetContentBoundsAsync();
74+
var round = await this.MainWindow.GetContentBoundsAsync();
7875
round.Width.Should().BeGreaterThan(0);
7976
round.Height.Should().BeGreaterThan(0);
8077
}
@@ -109,28 +106,28 @@ public async Task Show_hide_visibility_roundtrip()
109106
[IntegrationFact]
110107
public async Task AlwaysOnTop_toggle_and_query()
111108
{
112-
this.fx.MainWindow.SetAlwaysOnTop(true);
109+
this.MainWindow.SetAlwaysOnTop(true);
113110
await Task.Delay(500.ms());
114-
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeTrue();
115-
this.fx.MainWindow.SetAlwaysOnTop(false);
111+
(await this.MainWindow.IsAlwaysOnTopAsync()).Should().BeTrue();
112+
this.MainWindow.SetAlwaysOnTop(false);
116113
await Task.Delay(500.ms());
117-
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
114+
(await this.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
118115
}
119116

120117
[IntegrationFact]
121-
[SupportedOSPlatform("Linux")]
122-
[SupportedOSPlatform("Windows")]
118+
[SupportedOSPlatform(Linux)]
119+
[SupportedOSPlatform(Windows)]
123120
public async Task MenuBar_auto_hide_and_visibility()
124121
{
125-
this.fx.MainWindow.SetAutoHideMenuBar(true);
122+
this.MainWindow.SetAutoHideMenuBar(true);
126123
await Task.Delay(500.ms());
127-
(await this.fx.MainWindow.IsMenuBarAutoHideAsync()).Should().BeTrue();
128-
this.fx.MainWindow.SetMenuBarVisibility(false);
124+
(await this.MainWindow.IsMenuBarAutoHideAsync()).Should().BeTrue();
125+
this.MainWindow.SetMenuBarVisibility(false);
129126
await Task.Delay(500.ms());
130-
(await this.fx.MainWindow.IsMenuBarVisibleAsync()).Should().BeFalse();
131-
this.fx.MainWindow.SetMenuBarVisibility(true);
127+
(await this.MainWindow.IsMenuBarVisibleAsync()).Should().BeFalse();
128+
this.MainWindow.SetMenuBarVisibility(true);
132129
await Task.Delay(500.ms());
133-
(await this.fx.MainWindow.IsMenuBarVisibleAsync()).Should().BeTrue();
130+
(await this.MainWindow.IsMenuBarVisibleAsync()).Should().BeTrue();
134131
}
135132

136133
[IntegrationFact]
@@ -196,7 +193,7 @@ public async Task Resize_event_fires_on_size_change()
196193
[IntegrationFact]
197194
public async Task Progress_bar_and_always_on_top_toggle()
198195
{
199-
var win = this.fx.MainWindow;
196+
var win = this.MainWindow;
200197
win.SetProgressBar(0.5);
201198
await Task.Delay(50.ms());
202199
win.SetProgressBar(0.8, new ProgressBarOptions());
@@ -210,11 +207,11 @@ public async Task Progress_bar_and_always_on_top_toggle()
210207
}
211208

212209
[IntegrationFact]
213-
[SupportedOSPlatform("Linux")]
214-
[SupportedOSPlatform("Windows")]
210+
[SupportedOSPlatform(Linux)]
211+
[SupportedOSPlatform(Windows)]
215212
public async Task Menu_bar_visibility_and_auto_hide()
216213
{
217-
var win = this.fx.MainWindow;
214+
var win = this.MainWindow;
218215
win.SetAutoHideMenuBar(true);
219216
await Task.Delay(500.ms());
220217
(await win.IsMenuBarAutoHideAsync()).Should().BeTrue();
@@ -227,21 +224,21 @@ public async Task Menu_bar_visibility_and_auto_hide()
227224
public async Task Parent_child_relationship_roundtrip()
228225
{
229226
var child = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false, Width = 300, Height = 200 }, "about:blank");
230-
this.fx.MainWindow.SetParentWindow(null); // ensure top-level
231-
child.SetParentWindow(this.fx.MainWindow);
227+
this.MainWindow.SetParentWindow(null); // ensure top-level
228+
child.SetParentWindow(this.MainWindow);
232229
await Task.Delay(500.ms());
233230
var parent = await child.GetParentWindowAsync();
234-
parent.Id.Should().Be(this.fx.MainWindow.Id);
235-
var kids = await this.fx.MainWindow.GetChildWindowsAsync();
231+
parent.Id.Should().Be(this.MainWindow.Id);
232+
var kids = await this.MainWindow.GetChildWindowsAsync();
236233
kids.Select(k => k.Id).Should().Contain(child.Id);
237234
child.Destroy();
238235
}
239236

240237
[IntegrationFact]
241-
[SupportedOSPlatform("macOS")]
238+
[SupportedOSPlatform(MacOS)]
242239
public async Task Represented_filename_and_edited_flags()
243240
{
244-
var win = this.fx.MainWindow;
241+
var win = this.MainWindow;
245242
var temp = Path.Combine(Path.GetTempPath(), "electronnet_test.txt");
246243
File.WriteAllText(temp, "test");
247244
win.SetRepresentedFilename(temp);

src/ElectronNET.IntegrationTests/Tests/ClipboardTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ namespace ElectronNET.IntegrationTests.Tests
55
using ElectronNET.IntegrationTests.Common;
66

77
[Collection("ElectronCollection")]
8-
public class ClipboardTests
8+
public class ClipboardTests : IntegrationTestBase
99
{
10-
// ReSharper disable once NotAccessedField.Local
11-
private readonly ElectronFixture fx;
12-
13-
public ClipboardTests(ElectronFixture fx)
10+
public ClipboardTests(ElectronFixture fx) : base(fx)
1411
{
15-
this.fx = fx;
1612
}
1713

1814
[IntegrationFact]
@@ -34,8 +30,8 @@ public async Task Available_formats_contains_text_after_write()
3430
}
3531

3632
[IntegrationFact]
37-
[SupportedOSPlatform("macOS")]
38-
[SupportedOSPlatform("Windows")]
33+
[SupportedOSPlatform(MacOS)]
34+
[SupportedOSPlatform(Windows)]
3935
public async Task Bookmark_write_and_read()
4036
{
4137
var url = "https://electron-test.com";

src/ElectronNET.IntegrationTests/Tests/CookiesTests.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ namespace ElectronNET.IntegrationTests.Tests
44
using ElectronNET.IntegrationTests.Common;
55

66
[Collection("ElectronCollection")]
7-
public class CookiesTests
7+
public class CookiesTests : IntegrationTestBase
88
{
9-
private readonly ElectronFixture fx;
10-
11-
public CookiesTests(ElectronFixture fx)
9+
public CookiesTests(ElectronFixture fx) : base(fx)
1210
{
13-
this.fx = fx;
1411
}
1512

1613
[IntegrationFact(Skip = "Cookie set/get requires navigation to domain; skipping until test harness serves page")]
1714
public async Task Cookie_set_get_remove_sequence()
1815
{
19-
var session = this.fx.MainWindow.WebContents.Session;
16+
var session = this.MainWindow.WebContents.Session;
2017
var changed = false;
2118
session.Cookies.OnChanged += (cookie, cause, removed) => changed = true;
2219
// Navigate to example.com so cookie domain matches
23-
await this.fx.MainWindow.WebContents.LoadURLAsync("https://example.com");
20+
await this.MainWindow.WebContents.LoadURLAsync("https://example.com");
2421
// Set via renderer for now
25-
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
22+
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
2623
await Task.Delay(500.ms());
2724
changed.Should().BeTrue();
2825
}

src/ElectronNET.IntegrationTests/Tests/GlobalShortcutTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ namespace ElectronNET.IntegrationTests.Tests
55
using ElectronNET.IntegrationTests.Common;
66

77
[Collection("ElectronCollection")]
8-
public class GlobalShortcutTests
8+
public class GlobalShortcutTests : IntegrationTestBase
99
{
10+
public GlobalShortcutTests(ElectronFixture fx) : base(fx)
11+
{
12+
}
13+
1014
[IntegrationFact]
1115
public async Task Can_register_and_unregister()
1216
{

src/ElectronNET.IntegrationTests/Tests/HostHookTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ namespace ElectronNET.IntegrationTests.Tests
44
using ElectronNET.IntegrationTests.Common;
55

66
[Collection("ElectronCollection")]
7-
public class HostHookTests
7+
public class HostHookTests : IntegrationTestBase
88
{
9+
public HostHookTests(ElectronFixture fx) : base(fx)
10+
{
11+
}
12+
913
[IntegrationFact(Skip = "Requires HostHook setup; skipping")]
1014
public async Task HostHook_call_returns_value()
1115
{

0 commit comments

Comments
 (0)