48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using Omika.Diagnostics.Tests.Fakes;
|
|
|
|
namespace Omika.Diagnostics.Tests;
|
|
|
|
/// <summary>§55 — Traces : timeline chronologique pour un TraceId partagé (Mobile → API → Worker).</summary>
|
|
public class DiagnosticTraceTests
|
|
{
|
|
[Fact]
|
|
public async Task GetByTraceId_ReturnsChronologicalTimeline()
|
|
{
|
|
Guid traceId = Guid.NewGuid();
|
|
DateTimeOffset baseTime = new(2025, 1, 1, 10, 0, 0, TimeSpan.Zero);
|
|
|
|
var repository = new FakeDiagnosticEventRepository();
|
|
await repository.InsertBatchAsync(new[]
|
|
{
|
|
DiagnosticTestData.Event(Guid.NewGuid(), "MOBILE", baseTime.AddMinutes(2), traceId, component: "Mobile"),
|
|
DiagnosticTestData.Event(Guid.NewGuid(), "API", baseTime, traceId, component: "Api"),
|
|
DiagnosticTestData.Event(Guid.NewGuid(), "WORKER", baseTime.AddMinutes(1), traceId, component: "Worker")
|
|
});
|
|
|
|
var timeline = await repository.GetByTraceIdAsync(traceId);
|
|
|
|
Assert.Equal(3, timeline.Count);
|
|
Assert.Equal(new[] { "API", "WORKER", "MOBILE" }, timeline.Select(e => e.EventCode).ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetByOperationId_ReturnsChronologicalTimeline()
|
|
{
|
|
Guid operationId = Guid.NewGuid();
|
|
DateTimeOffset baseTime = new(2025, 1, 1, 12, 0, 0, TimeSpan.Zero);
|
|
|
|
var repository = new FakeDiagnosticEventRepository();
|
|
await repository.InsertBatchAsync(new[]
|
|
{
|
|
DiagnosticTestData.Event(Guid.NewGuid(), "SYNC_START", baseTime, operationId: operationId),
|
|
DiagnosticTestData.Event(Guid.NewGuid(), "SYNC_END", baseTime.AddSeconds(30), operationId: operationId)
|
|
});
|
|
|
|
var timeline = await repository.GetByOperationIdAsync(operationId);
|
|
|
|
Assert.Equal(2, timeline.Count);
|
|
Assert.Equal("SYNC_START", timeline[0].EventCode);
|
|
Assert.Equal("SYNC_END", timeline[1].EventCode);
|
|
}
|
|
}
|