using System; using System.IO; using Omika.App.Local.Security; namespace Omika.Tests.Mobile.Local; /// /// Tests de la distinction « mise à niveau d'une installation existante » vs /// « installation vierge / réinstallation », utilisée par iOS pour décider de /// purger ou non le Keychain. Aucun runtime iOS requis : logique pure. /// public class InstallationBootstrapperTests { private static string NewTempDir() { string dir = Path.Combine(Path.GetTempPath(), "omika-boot-" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(dir); return dir; } private static void DeleteDir(string dir) { try { Directory.Delete(dir, recursive: true); } catch { /* best-effort */ } } [Theory] [InlineData(true, true, InstallationKind.Normal)] [InlineData(true, false, InstallationKind.Normal)] [InlineData(false, true, InstallationKind.Upgrade)] [InlineData(false, false, InstallationKind.FreshInstall)] public void Decide_RetourneLaBonneNature(bool marker, bool proof, InstallationKind expected) => Assert.Equal(expected, InstallationBootstrapper.Decide(marker, proof)); [Fact] public void Decide_MarkerPresent_ToujoursNormal() => Assert.Equal(InstallationKind.Normal, InstallationBootstrapper.Decide(markerExists: true, hasHistoricalProof: false)); [Fact] public void Decide_MarkerAbsentSansPreuve_FreshInstall() => Assert.Equal(InstallationKind.FreshInstall, InstallationBootstrapper.Decide(markerExists: false, hasHistoricalProof: false)); [Fact] public void Decide_MarkerAbsentAvecPreuve_Upgrade() => Assert.Equal(InstallationKind.Upgrade, InstallationBootstrapper.Decide(markerExists: false, hasHistoricalProof: true)); [Fact] public void HasHistoricalProof_DossierInexistant_False() => Assert.False(InstallationBootstrapper.HasHistoricalProof(Path.Combine(Path.GetTempPath(), "omika-absent-" + Guid.NewGuid().ToString("N")))); [Fact] public void HasHistoricalProof_DossierVide_False() { string dir = NewTempDir(); try { Assert.False(InstallationBootstrapper.HasHistoricalProof(dir)); } finally { DeleteDir(dir); } } [Theory] [InlineData("device.id")] [InlineData("omika.db")] [InlineData("session.token")] [InlineData("session.token.secure")] public void HasHistoricalProof_TracePresente_True(string fileName) { string dir = NewTempDir(); try { File.WriteAllText(Path.Combine(dir, fileName), "x"); Assert.True(InstallationBootstrapper.HasHistoricalProof(dir)); } finally { DeleteDir(dir); } } }