CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
92 lines
4.3 KiB
C#
92 lines
4.3 KiB
C#
using System.Globalization;
|
||
using Chronos.App.Server;
|
||
using Chronos.App.Shell;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Windows.Services;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.App.Tests.Server;
|
||
|
||
/// <summary>
|
||
/// The desktop's lifetime while it shares its library (owner review 5, #67): closing hides to the tray while sharing, Exit
|
||
/// asks first when clients are active, a start at sign-in waits in the tray; with sharing off nothing changes.
|
||
/// </summary>
|
||
public sealed class ShareTrayTests
|
||
{
|
||
public ShareTrayTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
|
||
[Test]
|
||
public void ChronosOutlivesItsWindowOnlyWhileSharingIsOnOrOnItsWay()
|
||
{
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.On));
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.Starting));
|
||
// On in the settings, not started yet: the index is opening, or the archive's drive is unplugged.
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.Off));
|
||
Assert.False(ShareLifetime.KeepsRunning(shareEnabled: true, ShareState.Failed));
|
||
// Turned off and still stopping: the icon stays until it has stopped.
|
||
Assert.True(ShareLifetime.KeepsRunning(shareEnabled: false, ShareState.On));
|
||
Assert.False(ShareLifetime.KeepsRunning(shareEnabled: false, ShareState.Off));
|
||
Assert.False(ShareLifetime.KeepsRunning(shareEnabled: false, ShareState.Failed));
|
||
}
|
||
|
||
[Test]
|
||
public void ClosingHidesToTheTrayWhileSharingAndExitsOtherwise()
|
||
{
|
||
Assert.Equal(CloseAction.HideToTray, ShareLifetime.OnClose(exiting: false, keepsRunning: true));
|
||
Assert.Equal(CloseAction.Exit, ShareLifetime.OnClose(exiting: false, keepsRunning: false));
|
||
// Tray › Exit, or Windows ending the session: the window closes for real.
|
||
Assert.Equal(CloseAction.Exit, ShareLifetime.OnClose(exiting: true, keepsRunning: true));
|
||
Assert.Equal(CloseAction.Exit, ShareLifetime.OnClose(exiting: true, keepsRunning: false));
|
||
}
|
||
|
||
[Test]
|
||
public void ExitAsksFirstOnlyWhenClientsUseTheSharedLibrary()
|
||
{
|
||
Assert.True(ShareLifetime.AsksBeforeExit(ShareState.On, 1));
|
||
Assert.True(ShareLifetime.AsksBeforeExit(ShareState.On, 3));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.On, 0));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.Starting, 2));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.Failed, 2));
|
||
Assert.False(ShareLifetime.AsksBeforeExit(ShareState.Off, 2));
|
||
}
|
||
|
||
[Test]
|
||
public void TheExitQuestionKeepsSharingByDefaultAndCountsTheClients()
|
||
{
|
||
var one = ShellTray.ExitRequest(1);
|
||
Assert.Equal("Stop sharing?", one.Heading);
|
||
Assert.Equal("1 client used this library in the last minutes. Exiting Chronos stops sharing it.", one.Message);
|
||
Assert.Equal(("Keep sharing", "Exit"), (one.SafeText, one.ActionText));
|
||
Assert.False(one.IsDestructive);
|
||
Assert.Null(one.TypedConfirmation);
|
||
Assert.Contains("4 clients used", ShellTray.ExitRequest(4).Message);
|
||
}
|
||
|
||
[Test]
|
||
public void AStartAtSignInWaitsInTheTrayWhileSharingIsOn()
|
||
{
|
||
Assert.Equal(StartWindow.Tray, ShareLifetime.Start(minimized: true, shareEnabled: true));
|
||
Assert.Equal(StartWindow.Minimized, ShareLifetime.Start(minimized: true, shareEnabled: false));
|
||
Assert.Equal(StartWindow.Shown, ShareLifetime.Start(minimized: false, shareEnabled: true));
|
||
Assert.Equal(StartWindow.Shown, ShareLifetime.Start(minimized: false, shareEnabled: false));
|
||
}
|
||
|
||
[Test]
|
||
public void TheTrayToolTipNamesTheLibraryOrThisPc()
|
||
{
|
||
Assert.Equal("Chronos · sharing Studio", ShareLifetime.ToolTip(" Studio ", "STUDIO-PC"));
|
||
Assert.Equal("Chronos · sharing STUDIO-PC", ShareLifetime.ToolTip(null, "STUDIO-PC"));
|
||
Assert.Equal("Chronos · sharing STUDIO-PC", ShareLifetime.ToolTip(" ", "STUDIO-PC"));
|
||
}
|
||
|
||
[Test]
|
||
[WindowsOnly]
|
||
public void TheServiceProbeFindsInstalledServicesOnly()
|
||
{
|
||
// The event log service runs on every Windows; the probe asks connect and query-status rights only.
|
||
Assert.True(ServiceProbe.IsInstalled("EventLog"));
|
||
Assert.False(ServiceProbe.IsInstalled("ChronosNoSuchService" + Guid.NewGuid().ToString("N")));
|
||
Assert.Equal("ChronosServer", ServiceProbe.LegacyServer);
|
||
}
|
||
}
|