Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
using Omika.Core.Compatibility;
|
||||
using Omika.Core.Contracts.Mobile.Bootstrap;
|
||||
using Omika.Core.Contracts.Security;
|
||||
using Omika.Core.Interfaces.Mobile;
|
||||
using Omika.Core.Runtime;
|
||||
using Omika.Core.Services.Mobile;
|
||||
|
||||
namespace Omika.Tests.Mobile;
|
||||
|
||||
/// <summary>
|
||||
/// Tests du fournisseur d'identité mobile commun.
|
||||
/// Vérifie que le même DTO public est fourni pour Batik et Omika,
|
||||
/// sans que le mobile ne connaisse la génération de base.
|
||||
/// </summary>
|
||||
[Collection("ApplicationRuntimeContext")]
|
||||
public class MobileIdentityProviderTests : IDisposable
|
||||
{
|
||||
public MobileIdentityProviderTests()
|
||||
{
|
||||
ApplicationRuntimeContext.Reset();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ApplicationRuntimeContext.Reset();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetProfileAsync_Batik_Returns_Common_Profile()
|
||||
{
|
||||
// Arrange
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Batik);
|
||||
var provider = new MobileIdentityProvider(new FakeMobileIdentityRepository("BATIK"));
|
||||
|
||||
// Act
|
||||
var profile = await provider.GetProfileAsync("user-1");
|
||||
|
||||
// Assert : profil commun, sans révéler la génération.
|
||||
Assert.NotNull(profile);
|
||||
Assert.Equal("BATIK", profile.Code);
|
||||
Assert.False(profile.RoleSysteme);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetProfileAsync_Omika_Returns_Common_Profile()
|
||||
{
|
||||
// Arrange
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Omika);
|
||||
var provider = new MobileIdentityProvider(new FakeMobileIdentityRepository("OMIKA"));
|
||||
|
||||
// Act
|
||||
var profile = await provider.GetProfileAsync("user-1");
|
||||
|
||||
// Assert : profil commun, sans révéler la génération.
|
||||
Assert.NotNull(profile);
|
||||
Assert.Equal("OMIKA", profile.Code);
|
||||
Assert.False(profile.RoleSysteme);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetProfileAsync_Returns_Same_Contract_For_Batik_And_Omika()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new MobileIdentityProvider(new FakeMobileIdentityRepository("PROFIL"));
|
||||
|
||||
// Batik
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Batik);
|
||||
var batik = await provider.GetProfileAsync("user-1");
|
||||
|
||||
// Omika
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Omika);
|
||||
var omika = await provider.GetProfileAsync("user-1");
|
||||
|
||||
// Assert : le même type de contrat public est retourné.
|
||||
Assert.IsType<MobileProfileDto>(batik);
|
||||
Assert.IsType<MobileProfileDto>(omika);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPermissionsAsync_Returns_Empty_For_Batik()
|
||||
{
|
||||
// Arrange
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Batik);
|
||||
var provider = new MobileIdentityProvider(new FakeMobileIdentityRepository("BATIK"));
|
||||
|
||||
// Act
|
||||
var permissions = await provider.GetPermissionsAsync("user-1");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(permissions);
|
||||
Assert.Empty(permissions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPermissionsAsync_Returns_Empty_For_Omika()
|
||||
{
|
||||
// Arrange
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Omika);
|
||||
var provider = new MobileIdentityProvider(new FakeMobileIdentityRepository("OMIKA"));
|
||||
|
||||
// Act
|
||||
var permissions = await provider.GetPermissionsAsync("user-1");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(permissions);
|
||||
Assert.Empty(permissions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetProfileAsync_Empty_UserId_Throws()
|
||||
{
|
||||
// Arrange
|
||||
ApplicationRuntimeContext.Configure(DatabaseSchemaSelection.Auto);
|
||||
ApplicationRuntimeContext.SetDetectedVersion(DatabaseSchemaVersion.Batik);
|
||||
var provider = new MobileIdentityProvider(new FakeMobileIdentityRepository("BATIK"));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<ArgumentException>(
|
||||
() => provider.GetProfileAsync(""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPermissionsAsync_Returns_Repository_Permissions()
|
||||
{
|
||||
// Arrange
|
||||
var repo = new FakeMobileIdentityRepository("PROFIL");
|
||||
repo.Permissions["DOC.LIRE"] = true;
|
||||
var provider = new MobileIdentityProvider(repo);
|
||||
|
||||
// Act
|
||||
var permissions = await provider.GetPermissionsAsync("user-1");
|
||||
|
||||
// Assert
|
||||
Assert.True(permissions["DOC.LIRE"]);
|
||||
}
|
||||
|
||||
// ===== Fake =====
|
||||
|
||||
private sealed class FakeMobileIdentityRepository : IMobileIdentityRepository
|
||||
{
|
||||
private readonly string _profileCode;
|
||||
|
||||
public FakeMobileIdentityRepository(string profileCode)
|
||||
{
|
||||
_profileCode = profileCode;
|
||||
}
|
||||
|
||||
public Dictionary<string, bool> Permissions { get; } = [];
|
||||
|
||||
public Task<MobileProfileDto> GetProfileAsync(string userId, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult(new MobileProfileDto
|
||||
{
|
||||
Code = _profileCode,
|
||||
Nom = _profileCode,
|
||||
Description = _profileCode,
|
||||
RoleSysteme = false
|
||||
});
|
||||
|
||||
public Task<IReadOnlyDictionary<string, bool>> GetPermissionsAsync(string userId, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult<IReadOnlyDictionary<string, bool>>(Permissions);
|
||||
|
||||
public Task<string?> GetLoginByUserIdAsync(string userId, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult<string?>(null);
|
||||
|
||||
public Task<long?> GetUtilisateurPkIdByCollaborateurAsync(long collaborateurPkId, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult<long?>(null);
|
||||
|
||||
public Task<string?> GetLoginByCollaborateurAsync(long collaborateurPkId, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult<string?>(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user