Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using Omika.Core.Observability.External;
|
||||
using Omika.Core.Observability.Outbox;
|
||||
using Omika.Tests.Observability.Forwarding;
|
||||
|
||||
namespace Omika.Tests.Observability.Outbox;
|
||||
|
||||
/// <summary>Tests de la validation du lot central (réutilisation de la whitelist Phase 4).</summary>
|
||||
public class CentralDiagnosticBatchValidatorTests
|
||||
{
|
||||
private static CentralDiagnosticOptions Limits() => new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_ValidBatch_ReturnsValid()
|
||||
{
|
||||
var batch = new CentralDiagnosticBatchDto { Events = [ForwardingTestHarness.NewRecord()] };
|
||||
|
||||
CentralDiagnosticValidationResult result = CentralDiagnosticBatchValidator.Validate(batch, Limits());
|
||||
|
||||
Assert.True(result.IsValid);
|
||||
Assert.Null(result.Reason);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_NullBatch_Invalid() =>
|
||||
Assert.False(CentralDiagnosticBatchValidator.Validate(null, Limits()).IsValid);
|
||||
|
||||
[Fact]
|
||||
public void Validate_EmptyEvents_Invalid() =>
|
||||
Assert.False(CentralDiagnosticBatchValidator.Validate(new CentralDiagnosticBatchDto(), Limits()).IsValid);
|
||||
|
||||
[Fact]
|
||||
public void Validate_TooManyEvents_Invalid()
|
||||
{
|
||||
var batch = new CentralDiagnosticBatchDto
|
||||
{
|
||||
Events = Enumerable.Range(0, 101).Select(_ => ForwardingTestHarness.NewRecord()).ToList()
|
||||
};
|
||||
|
||||
Assert.False(CentralDiagnosticBatchValidator.Validate(batch, Limits()).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_NullEvent_Invalid()
|
||||
{
|
||||
var batch = new CentralDiagnosticBatchDto { Events = [(RemoteDiagnosticRecord)null!] };
|
||||
|
||||
Assert.False(CentralDiagnosticBatchValidator.Validate(batch, Limits()).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_InvalidEventCode_Invalid()
|
||||
{
|
||||
RemoteDiagnosticRecord record = ForwardingTestHarness.NewRecord();
|
||||
var bad = new RemoteDiagnosticRecord
|
||||
{
|
||||
ReceivedAtUtc = record.ReceivedAtUtc,
|
||||
Event = new DiagnosticEventDto { EventId = Guid.NewGuid(), EventCode = string.Empty }
|
||||
};
|
||||
|
||||
Assert.False(CentralDiagnosticBatchValidator.Validate(new CentralDiagnosticBatchDto { Events = [bad] }, Limits()).IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_ForbiddenMetadataKey_Invalid()
|
||||
{
|
||||
RemoteDiagnosticRecord record = ForwardingTestHarness.NewRecord();
|
||||
var bad = new RemoteDiagnosticRecord
|
||||
{
|
||||
ReceivedAtUtc = record.ReceivedAtUtc,
|
||||
Event = new DiagnosticEventDto
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
EventCode = "OMK-MOB-APP-001",
|
||||
Metadata = new Dictionary<string, object?> { ["password"] = "x" }
|
||||
}
|
||||
};
|
||||
|
||||
Assert.False(CentralDiagnosticBatchValidator.Validate(new CentralDiagnosticBatchDto { Events = [bad] }, Limits()).IsValid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user