Skip to content

Commit 6f22fa2

Browse files
Test that applications without a shell boot headless (#654)
Booting without a shell, directly or through the Generic Host, must not show or set a main window, so that applications can start hidden, for example in the tray area. Closes #250
1 parent 6ae7348 commit 6f22fa2

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎src/Radical.Windows.Tests/Boot/RadicalApplicationTests.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ public void ApplicationBoot_process_should_create_valid_container()
3030
Assert.IsTrue(bootCompleted);
3131
}
3232

33+
[SharedApplicationTestMethod]
34+
public void Application_without_a_shell_boots_without_showing_windows()
35+
{
36+
var bootCompleted = false;
37+
var mainWindowBeforeBoot = Application.Current.MainWindow;
38+
var windowsBeforeBoot = Application.Current.Windows.Count;
39+
40+
var radicalApplication = Application.Current.AddRadicalApplication(configuration =>
41+
{
42+
configuration.DisableAutoBoot();
43+
configuration.OnBootCompleted(_ => bootCompleted = true);
44+
});
45+
46+
radicalApplication.Boot();
47+
48+
Assert.IsTrue(bootCompleted);
49+
Assert.AreSame(mainWindowBeforeBoot, Application.Current.MainWindow);
50+
Assert.AreEqual(windowsBeforeBoot, Application.Current.Windows.Count);
51+
}
52+
3353
[SharedApplicationTestMethod]
3454
public void ApplicationBoot_process_should_allow_services_customization()
3555
{

‎src/Radical.Windows.Tests/Boot/RadicalApplicationTestsWithGenericHost.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ public async Task Application_can_boot_using_host_builder()
3838
}
3939
}
4040

41+
[SharedApplicationTestMethod]
42+
public async Task Application_without_a_shell_using_host_builder_boots_without_showing_windows()
43+
{
44+
var bootCompleted = false;
45+
var mainWindowBeforeBoot = Application.Current.MainWindow;
46+
var windowsBeforeBoot = Application.Current.Windows.Count;
47+
48+
var host = new HostBuilder()
49+
.AddRadicalApplication(configuration =>
50+
{
51+
configuration.OnBootCompleted(_ => bootCompleted = true);
52+
})
53+
.Build();
54+
55+
await host.StartAsync();
56+
57+
Assert.IsTrue(bootCompleted);
58+
Assert.AreSame(mainWindowBeforeBoot, Application.Current.MainWindow);
59+
Assert.AreEqual(windowsBeforeBoot, Application.Current.Windows.Count);
60+
61+
using (host)
62+
{
63+
await host.StopAsync();
64+
}
65+
}
66+
4167
[SharedApplicationTestMethod]
4268
public async Task Application_using_host_builder_can_resolve_configured_services()
4369
{

0 commit comments

Comments
 (0)