using Titano.App.Infrastructure; using Titano.Core.IO; using Titano.Testing; namespace Titano.App.Tests.Infrastructure; /// Settings › General › Startup: one sign-in entry shared by every copy of Titano, which no copy takes over by starting. public sealed class StartWithWindowsTests { private const string Installed = @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.exe"; [Test] public void AStartFollowsOnlyAnEntryAnUpdateLeftBehindInItsOwnFolder() { static bool Gone(string path) => false; static bool Present(string path) => true; var installed = StartupCommand.Format(Installed, RunKeyStartWithWindows.MinimizedOption); // The entry already starts this copy: nothing to write. Assert.False(RunKeyStartWithWindows.Follows(installed, Installed, Gone)); // An update renamed the program in its folder: the entry follows it. Assert.True(RunKeyStartWithWindows.Follows(StartupCommand.Format(@"C:\Users\ada\AppData\Local\Programs\Titano\Titano.old.exe", "--minimized"), Installed, Gone)); // The installed copy is still there: a portable copy, a second install or a development build that starts leaves it alone. Assert.False(RunKeyStartWithWindows.Follows(installed, @"E:\Titano\Titano.exe", Present)); Assert.False(RunKeyStartWithWindows.Follows(installed, @"C:\src\Titano\bin\Debug\Titano.exe", Present)); // Gone from another folder (a USB stick that is not plugged in): still not this copy's entry. Assert.False(RunKeyStartWithWindows.Follows(installed, @"E:\Titano\Titano.exe", Gone)); // No entry, or no executable path: nothing to follow. Assert.False(RunKeyStartWithWindows.Follows(null, Installed, Gone)); Assert.False(RunKeyStartWithWindows.Follows(installed, null, Gone)); } [Test] public void ScreenshotsAndPortableCopiesKeepTheChoiceInMemory() { var startup = new MemoryStartWithWindows(); Assert.False(startup.IsEnabled); startup.SetEnabled(true); startup.Refresh(); Assert.True(startup.IsEnabled); startup.SetEnabled(false); Assert.False(startup.IsEnabled); } }