86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using Omika.App.Local.Abstractions;
|
|
using Omika.App.Local.Models;
|
|
using Omika.App.Local.Repositories;
|
|
using Omika.App.Local.Services;
|
|
|
|
namespace Omika.Tests.Mobile.Local;
|
|
|
|
/// <summary>
|
|
/// Tests du stockage local d'inscription + réinitialisation complète.
|
|
/// </summary>
|
|
public class MobileEnrollmentStoreTests : LocalTestBase
|
|
{
|
|
private static MobileEnrollmentConfiguration NewConfig()
|
|
=> new()
|
|
{
|
|
Version = 1,
|
|
CodeClient = "BATIK.01",
|
|
NumeroLicence = "LIC-001",
|
|
LicenseServiceUrl = "https://licence.example.com",
|
|
OmikaApiUrl = "https://api.example.com",
|
|
EnrolledAtUtc = DateTimeOffset.UtcNow
|
|
};
|
|
|
|
private sealed class FakeTokenStore : ISecureTokenStore
|
|
{
|
|
public bool Cleared { get; private set; }
|
|
|
|
public Task SaveAsync(string token, CancellationToken cancellationToken = default)
|
|
=> Task.CompletedTask;
|
|
|
|
public Task<string?> GetAsync(CancellationToken cancellationToken = default)
|
|
=> Task.FromResult<string?>(null);
|
|
|
|
public Task ClearAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
Cleared = true;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SavePuisLoad_RestaureOmikaApiUrl()
|
|
{
|
|
var store = new MobileEnrollmentStore(Database);
|
|
await store.SaveAsync(NewConfig());
|
|
|
|
MobileEnrollmentConfiguration? loaded = await store.LoadAsync();
|
|
|
|
Assert.NotNull(loaded);
|
|
Assert.Equal("https://api.example.com", loaded!.OmikaApiUrl);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Load_SansInscription_RetourneNull()
|
|
{
|
|
var store = new MobileEnrollmentStore(Database);
|
|
Assert.Null(await store.LoadAsync());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Reset_SupprimeUrlLicenceEtUrlApi()
|
|
{
|
|
var store = new MobileEnrollmentStore(Database);
|
|
await store.SaveAsync(NewConfig());
|
|
|
|
var maintenance = new LocalDataMaintenanceService(Database, "unused", new FakeTokenStore());
|
|
await maintenance.ResetAsync();
|
|
|
|
Assert.Null(await store.LoadAsync());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Reset_SupprimeTokenSession()
|
|
{
|
|
var store = new MobileEnrollmentStore(Database);
|
|
await store.SaveAsync(NewConfig());
|
|
var tokenStore = new FakeTokenStore();
|
|
|
|
var maintenance = new LocalDataMaintenanceService(Database, "unused", tokenStore);
|
|
await maintenance.ResetAsync();
|
|
|
|
Assert.True(tokenStore.Cleared);
|
|
Assert.Null(await store.LoadAsync());
|
|
}
|
|
}
|