using Febe.App; using Febe.Core.Library; using Febe.Desktop.Core; using Febe.Tests.Desktop.Support; using Febe.Tests.Support; using Febe.Web.Engine; namespace Febe.Tests.Desktop; /// /// Issue #36, S4, spec §12 and §13.2, on the Windows side without Windows: the option «raccolta» of Febe.exe (pages by /// default) and the protector of the saved session, which comes from the Windows-only shell (DPAPI there, a fake here). /// [TestClass] public sealed class DesktopSessionOptionsTests { [TestMethod] public void TheCommandLineReadsRaccoltaAndPagesIsTheDefault() { var folders = new DesktopFolders("a", "b"); Assert.IsTrue(DesktopCommandLine.TryParse([], out var plain, out var problem), problem); Assert.AreEqual(CollectionRoute.Pages, plain.Collection, "nothing changes by default"); Assert.AreEqual(CollectionRoute.Pages, plain.AppOptions("c", folders).Collection); Assert.IsTrue(DesktopCommandLine.TryParse(["--sito-di-prova", "http://127.0.0.1:8481", "--raccolta", "RICHIESTE"], out var requests, out problem), problem); Assert.AreEqual(CollectionRoute.Requests, requests.Collection); Assert.AreEqual(CollectionRoute.Requests, requests.AppOptions("c", folders).Collection); Assert.IsFalse(DesktopCommandLine.TryParse(["--raccolta", "browser"], out _, out problem)); StringAssert.Contains(problem, "pagine oppure richieste"); Assert.IsFalse(DesktopCommandLine.TryParse(["--raccolta"], out _, out problem)); StringAssert.Contains(problem, "Dopo --raccolta"); StringAssert.Contains(DesktopCommandLine.Usage, "--raccolta pagine|richieste"); } [TestMethod] public void TheProtectorIsTheShellsAndTheLogNamesOnlyItsScheme() { using var temp = new TempFolder("desktop-sessione"); using var console = new StringWriter(); var clock = new ManualClock(new DateTimeOffset(2026, 11, 17, 10, 0, 0, TimeSpan.Zero)); using var log = new FebeLog(null, console, clock); var shell = new FakeDesktopShell(); var platform = new DesktopPlatform(new DesktopOptions(), shell, new MemoryLocationStore(), dataFolderFixed: true); var data = new DataFolderLayout(temp.Combine("dati")); var context = new FebePlatformContext( new FebeAppOptions { DataFolder = data.Root, LibraryFolder = temp.Combine("libreria") }, data, null!, clock, log, new BrowserUseTracker()); var protector = platform.CreateSessionProtector(context); Assert.AreSame(shell.SessionProtector, protector); StringAssert.Contains(console.ToString(), "Sessione salvata: cifrata con " + protector.Scheme); Assert.IsFalse(Directory.Exists(data.Session), "no key file on Windows: DPAPI needs none"); } }