Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using Omika.Data.Configuration;
|
||||
using Omika.Data.Connection;
|
||||
using Omika.Data.Repositories.Technical;
|
||||
|
||||
namespace Omika.Tests.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Tests du repository de licence pour la résolution multi-client de l'URL API
|
||||
/// (<c>ClientBase.CL_IDWebServiceMobile</c> → <c>ServeurWebService.WS_AdresseAWP</c>).
|
||||
/// </summary>
|
||||
public class LicenceRepositoryTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task GetMobileApiUrlForClientAsync_JointureParametree_RetourneAdresse()
|
||||
{
|
||||
var connection = new FakeHfsqlConnection(HfsqlConnectionState.Open);
|
||||
connection.QueryResult =
|
||||
[
|
||||
new Dictionary<string, object?> { ["WS_PKID"] = 10L, ["WS_AdresseAWP"] = "https://api-a.example.test" }
|
||||
];
|
||||
var repository = new LicenceRepository(connection);
|
||||
|
||||
string? url = await repository.GetMobileApiUrlForClientAsync("CLIENT.A");
|
||||
|
||||
Assert.Equal("https://api-a.example.test", url);
|
||||
Assert.Contains("JOIN ServeurWebService", connection.LastSql);
|
||||
Assert.Contains("ClientBase.CL_Code = ?", connection.LastSql);
|
||||
Assert.DoesNotContain("CLIENT.A", connection.LastSql); // CodeClient non concaténé
|
||||
Assert.NotNull(connection.LastParameters);
|
||||
Assert.Single(connection.LastParameters!);
|
||||
Assert.Equal("CLIENT.A", connection.LastParameters![0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetMobileApiUrlForClientAsync_AucuneLigne_RetourneNull()
|
||||
{
|
||||
var connection = new FakeHfsqlConnection(HfsqlConnectionState.Open);
|
||||
connection.QueryResult = [];
|
||||
var repository = new LicenceRepository(connection);
|
||||
|
||||
Assert.Null(await repository.GetMobileApiUrlForClientAsync("CLIENT.INCONNU"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetMobileApiUrlForClientAsync_CodeVide_RetourneNullSansRequete()
|
||||
{
|
||||
var connection = new FakeHfsqlConnection(HfsqlConnectionState.Open);
|
||||
var repository = new LicenceRepository(connection);
|
||||
|
||||
Assert.Null(await repository.GetMobileApiUrlForClientAsync(" "));
|
||||
Assert.Equal(0, connection.QueryCount);
|
||||
}
|
||||
|
||||
private sealed class FakeHfsqlConnection : IHfsqlConnection
|
||||
{
|
||||
public FakeHfsqlConnection(HfsqlConnectionState state) => State = state;
|
||||
|
||||
public HfsqlOptions Options => new();
|
||||
public HfsqlConnectionState State { get; private set; }
|
||||
|
||||
public string? LastSql { get; private set; }
|
||||
public IReadOnlyList<object?>? LastParameters { get; private set; }
|
||||
public int QueryCount { get; private set; }
|
||||
public IReadOnlyList<IReadOnlyDictionary<string, object?>> QueryResult { get; set; } = [];
|
||||
|
||||
public Task OpenAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
State = HfsqlConnectionState.Open;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task CloseAsync()
|
||||
{
|
||||
State = HfsqlConnectionState.Closed;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
|
||||
public Task<object?> ExecuteScalarAsync(string sql, IReadOnlyList<object?>? parameters = null, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult<object?>(null);
|
||||
|
||||
public Task<int> ExecuteNonQueryAsync(string sql, IReadOnlyList<object?>? parameters = null, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult(0);
|
||||
|
||||
public Task<IReadOnlyList<IReadOnlyDictionary<string, object?>>> QueryAsync(string sql, IReadOnlyList<object?>? parameters = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
QueryCount++;
|
||||
LastSql = sql;
|
||||
LastParameters = parameters;
|
||||
return Task.FromResult(QueryResult);
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<HfsqlColumnMetadata>> GetColumnsAsync(string tableName, CancellationToken cancellationToken = default)
|
||||
=> Task.FromResult<IReadOnlyList<HfsqlColumnMetadata>>([]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user