Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using Omika.Diagnostics.Queries;
|
||||
using Omika.Diagnostics.Tests.Fakes;
|
||||
|
||||
namespace Omika.Diagnostics.Tests;
|
||||
|
||||
/// <summary>§56 — Pagination : page size borné, offset calculé, tri timestamp, jamais de requête non bornée.</summary>
|
||||
public class DiagnosticPaginationTests
|
||||
{
|
||||
[Fact]
|
||||
public void Query_ClampsPageSizeAndPage()
|
||||
{
|
||||
var tooLarge = new DiagnosticEventQuery { PageSize = 100_000, Page = 0 };
|
||||
Assert.Equal(DiagnosticPaging.MaxPageSize, tooLarge.PageSize);
|
||||
Assert.Equal(1, tooLarge.Page);
|
||||
Assert.Equal(0, tooLarge.Offset);
|
||||
|
||||
var tooSmall = new DiagnosticEventQuery { PageSize = 0 };
|
||||
Assert.Equal(1, tooSmall.PageSize);
|
||||
|
||||
var page3 = new DiagnosticEventQuery { Page = 3, PageSize = 50 };
|
||||
Assert.Equal(100, page3.Offset);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Repository_AppliesBoundedPagination()
|
||||
{
|
||||
var repository = new FakeDiagnosticEventRepository();
|
||||
DateTimeOffset baseTime = new(2025, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
await repository.InsertBatchAsync(new[]
|
||||
{
|
||||
DiagnosticTestData.Event(Guid.NewGuid(), "E" + i, baseTime.AddSeconds(i))
|
||||
});
|
||||
}
|
||||
|
||||
var page = await repository.QueryAsync(new DiagnosticEventQuery { Page = 2, PageSize = 3 });
|
||||
|
||||
Assert.Equal(10, page.TotalCount);
|
||||
Assert.Equal(4, page.TotalPages);
|
||||
Assert.Equal(3, page.Items.Count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user