107 lines
5.7 KiB
C#
107 lines
5.7 KiB
C#
using Omika.App.Local.Abstractions;
|
|
using Omika.App.Local.Models;
|
|
using Omika.App.Local.Repositories;
|
|
using Omika.App.Local.Services;
|
|
using Omika.App.Local.Sqlite;
|
|
|
|
namespace Omika.Tests.Mobile.Local;
|
|
|
|
/// <summary>
|
|
/// Base de test pour l'infrastructure locale offline-first.
|
|
/// Crée une base SQLite en mémoire avec le schéma complet.
|
|
/// </summary>
|
|
public abstract class LocalTestBase : IDisposable
|
|
{
|
|
protected LocalDatabase Database { get; }
|
|
protected LocalRepository<LocalClient> ClientRepository { get; }
|
|
protected LocalRepository<LocalSite> SiteRepository { get; }
|
|
protected LocalRepository<LocalIntervention> InterventionRepository { get; }
|
|
protected LocalRepository<LocalRendezVous> RendezVousRepository { get; }
|
|
protected LocalRepository<LocalDossier> DossierRepository { get; }
|
|
protected LocalRepository<LocalDocumentMetadata> DocumentMetadataRepository { get; }
|
|
protected LocalRepository<LocalPersonne> PersonneRepository { get; }
|
|
protected LocalRepository<LocalCollaborateur> CollaborateurRepository { get; }
|
|
protected LocalRepository<LocalSuiviTemps> SuiviTempsRepository { get; }
|
|
|
|
|
|
|
|
|
|
protected OutboxRepository OutboxRepository { get; }
|
|
protected IdentityMappingRepository IdentityMappingRepository { get; }
|
|
protected DocumentCacheRepository DocumentCacheRepository { get; }
|
|
protected NoteDocumentLocalRepository NoteDocumentRepository { get; }
|
|
protected SyncStateRepository SyncStateRepository { get; }
|
|
protected LocalBootstrapRepository BootstrapRepository { get; }
|
|
protected SuiviTempsDraftRepository SuiviTempsDraftRepository { get; }
|
|
protected RendezVousTempsValidationRepository RendezVousTempsValidationRepository { get; }
|
|
protected PreferencesUtilisateurRepository PreferencesUtilisateurRepository { get; }
|
|
protected IOutboxService OutboxService { get; }
|
|
protected IMobileIdentityReconciliationService ReconciliationService { get; }
|
|
protected InterventionCacheRepository InterventionCacheRepository { get; }
|
|
protected IContextInterventionCacheRepository ContextInterventionCacheRepository { get; }
|
|
protected DossierLocalStateRepository DossierStateRepository { get; }
|
|
protected ClientLocalStateRepository ClientStateRepository { get; }
|
|
protected SiteLocalStateRepository SiteStateRepository { get; }
|
|
protected IDossierInterventionCacheRepository DossierInterventionCacheRepository { get; }
|
|
protected IMobileApiClient ApiClient { get; }
|
|
protected StubSessionService SessionService { get; } = new();
|
|
|
|
/// <summary>Connectivité simulée partagée (online par défaut).</summary>
|
|
protected FakeNetwork Network { get; } = new();
|
|
|
|
protected LocalTestBase()
|
|
{
|
|
Database = new LocalDatabase(new LocalDatabaseOptions());
|
|
Database.InitializeSchemaAsync().GetAwaiter().GetResult();
|
|
|
|
ClientRepository = new LocalRepository<LocalClient>(Database, "Client", []);
|
|
SiteRepository = new LocalRepository<LocalSite>(Database, "Site", ["ClientId"]);
|
|
InterventionRepository = new LocalRepository<LocalIntervention>(Database, "Intervention", ["ClientId", "SiteId", "DossierId"]);
|
|
RendezVousRepository = new LocalRepository<LocalRendezVous>(Database, "RendezVous", ["ClientId", "SiteId", "DossierId", "InterventionId"]);
|
|
DossierRepository = new LocalRepository<LocalDossier>(Database, "Dossier", ["ClientId", "SiteId"]);
|
|
DocumentMetadataRepository = new LocalRepository<LocalDocumentMetadata>(Database, "DocumentMetadata", ["InterventionId"]);
|
|
PersonneRepository = new LocalRepository<LocalPersonne>(Database, "Personne", ["ClientId"]);
|
|
CollaborateurRepository = new LocalRepository<LocalCollaborateur>(Database, "Collaborateur", ["SocieteId"]);
|
|
SuiviTempsRepository = new LocalRepository<LocalSuiviTemps>(Database, "SuiviTemps", ["CollaborateurId", "InterventionId", "RendezVousId"]);
|
|
OutboxRepository = new OutboxRepository(Database);
|
|
|
|
|
|
|
|
|
|
IdentityMappingRepository = new IdentityMappingRepository(Database);
|
|
DocumentCacheRepository = new DocumentCacheRepository(Database);
|
|
NoteDocumentRepository = new NoteDocumentLocalRepository(Database);
|
|
SyncStateRepository = new SyncStateRepository(Database);
|
|
BootstrapRepository = new LocalBootstrapRepository(Database);
|
|
SuiviTempsDraftRepository = new SuiviTempsDraftRepository(Database);
|
|
RendezVousTempsValidationRepository = new RendezVousTempsValidationRepository(Database);
|
|
PreferencesUtilisateurRepository = new PreferencesUtilisateurRepository(Database);
|
|
|
|
OutboxService = new OutboxService(OutboxRepository);
|
|
ReconciliationService = new MobileIdentityReconciliationService(
|
|
Database, IdentityMappingRepository, OutboxRepository, []);
|
|
InterventionCacheRepository = new InterventionCacheRepository(Database);
|
|
ContextInterventionCacheRepository = new ContextInterventionCacheRepository(Database);
|
|
DossierStateRepository = new DossierLocalStateRepository(Database);
|
|
ClientStateRepository = new ClientLocalStateRepository(Database);
|
|
SiteStateRepository = new SiteLocalStateRepository(Database);
|
|
DossierInterventionCacheRepository = new DossierInterventionCacheRepository(Database);
|
|
ApiClient = new StubMobileApiClient();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Database.Dispose();
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
/// <summary>Connectivité réseau simulée (online par défaut, modifiable par test).</summary>
|
|
protected sealed class FakeNetwork : INetworkConnectivity
|
|
{
|
|
public bool Online { get; set; } = true;
|
|
|
|
public Task<bool> IsOnlineAsync(CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(Online);
|
|
}
|
|
}
|