Files
Heimdall/tests/Heimdall.Domain.Tests/Entities/BusinessEntityTests.cs
T

187 lines
6.3 KiB
C#

using Heimdall.Domain.Entities;
using Heimdall.Domain.Enums;
using Shouldly;
namespace Heimdall.Domain.Tests.Entities;
public class BusinessEntityTests
{
// ─── StoragePolicy ─────────────────────────────────────────────
[Fact]
public void StoragePolicy_create_should_set_properties()
{
var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3);
policy.Name.ShouldBe("30 jours");
policy.RetentionDays.ShouldBe(30);
policy.StorageProvider.ShouldBe(StorageProvider.S3);
policy.Id.ShouldNotBe(Guid.Empty);
}
[Fact]
public void StoragePolicy_update_should_change_values()
{
var policy = new StoragePolicy("30 jours", 30, StorageProvider.S3);
policy.Update("90 jours", 90, StorageProvider.Local);
policy.Name.ShouldBe("90 jours");
policy.RetentionDays.ShouldBe(90);
policy.StorageProvider.ShouldBe(StorageProvider.Local);
}
// ─── Vehicle ───────────────────────────────────────────────────
[Fact]
public void Vehicle_create_should_set_properties()
{
var vehicle = new Vehicle("AB-123-CD", null, "Renault", "Clio", "Noir");
vehicle.LicensePlate.ShouldBe("AB-123-CD");
vehicle.Make.ShouldBe("Renault");
vehicle.Model.ShouldBe("Clio");
vehicle.Color.ShouldBe("Noir");
}
[Fact]
public void Vehicle_assign_person_should_set_relation()
{
var vehicle = new Vehicle("AB-123-CD");
var personId = Guid.NewGuid();
vehicle.AssignPerson(personId);
vehicle.PersonId.ShouldBe(personId);
}
// ─── Recording ─────────────────────────────────────────────────
[Fact]
public void Recording_create_should_set_properties()
{
var cameraId = Guid.NewGuid();
var policyId = Guid.NewGuid();
var ts = new DateTime(2026, 7, 1, 12, 0, 0, DateTimeKind.Utc);
var recording = new Recording(cameraId, ts, 60.0, "recordings/2026/07/01/12/cam1.mp4", 10_000_000,
StorageProvider.S3, new StorageLocation(StorageProvider.S3, S3Endpoint: "https://storage.test", S3Bucket: "heimdall"), policyId);
recording.CameraId.ShouldBe(cameraId);
recording.Timestamp.ShouldBe(ts);
recording.DurationSeconds.ShouldBe(60.0);
recording.StoragePath.ShouldBe("recordings/2026/07/01/12/cam1.mp4");
recording.SizeBytes.ShouldBe(10_000_000L);
recording.StorageProvider.ShouldBe(StorageProvider.S3);
recording.StoragePolicyId.ShouldBe(policyId);
}
[Fact]
public void Recording_assign_policy_should_update_relation()
{
var recording = new Recording(Guid.NewGuid(), DateTime.UtcNow, 60, "path.mp4", 100,
StorageProvider.Local, new StorageLocation(StorageProvider.Local, LocalRoot: "/tmp/heimdall-storage"));
var policyId = Guid.NewGuid();
recording.AssignStoragePolicy(policyId);
recording.StoragePolicyId.ShouldBe(policyId);
}
// ─── LicensePlate ──────────────────────────────────────────────
[Fact]
public void LicensePlate_create_should_set_properties()
{
var plate = new LicensePlate("AB-123-CD", null, null, 0.98);
plate.PlateText.ShouldBe("AB-123-CD");
plate.Confidence.ShouldBe(0.98);
}
[Fact]
public void LicensePlate_assign_vehicle_and_person_should_set_relations()
{
var plate = new LicensePlate("AB-123-CD");
var vehicleId = Guid.NewGuid();
var personId = Guid.NewGuid();
plate.AssignVehicle(vehicleId);
plate.AssignPerson(personId);
plate.VehicleId.ShouldBe(vehicleId);
plate.PersonId.ShouldBe(personId);
}
[Theory]
[InlineData(0.0)]
[InlineData(1.0)]
public void LicensePlate_should_accept_confidence_bounds(double confidence)
{
var plate = new LicensePlate("AB-123-CD", confidence: confidence);
plate.Confidence.ShouldBe(confidence);
}
[Theory]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
[InlineData(-0.01)]
[InlineData(1.01)]
public void LicensePlate_should_reject_invalid_confidence(double confidence)
{
Should.Throw<ArgumentOutOfRangeException>(() => new LicensePlate("AB-123-CD", confidence: confidence));
}
[Fact]
public void LicensePlate_should_reject_text_over_database_limit()
{
Should.Throw<ArgumentException>(() => new LicensePlate(new string('A', LicensePlate.MaxPlateTextLength + 1)));
}
// ─── CameraEvent — relations enrichies (spec 2.2) ─────────────
[Fact]
public void CameraEvent_assign_vehicle_recording_and_parent_should_set_relations()
{
var evt = new CameraEvent(Guid.NewGuid(), EventType.VehicleDetected, 0.9);
var vehicleId = Guid.NewGuid();
var recordingId = Guid.NewGuid();
var parentId = Guid.NewGuid();
evt.AssignVehicle(vehicleId);
evt.AssignRecording(recordingId);
evt.AssignParentEvent(parentId);
evt.VehicleId.ShouldBe(vehicleId);
evt.RecordingId.ShouldBe(recordingId);
evt.ParentEventId.ShouldBe(parentId);
}
[Fact]
public void CameraEvent_dedup_fields_should_be_settable()
{
var evt = new CameraEvent(Guid.NewGuid(), EventType.PersonDetected, 0.85);
evt.SetTrackId("track-42");
evt.SetDetectionHash("sha256:abc123");
evt.SetSuppressed(true);
evt.TrackId.ShouldBe("track-42");
evt.DetectionHash.ShouldBe("sha256:abc123");
evt.IsSuppressed.ShouldBeTrue();
}
// ─── Camera → StoragePolicy (N:1) ──────────────────────────────
[Fact]
public void Camera_assign_storage_policy_should_set_relation()
{
var camera = new Camera(Guid.NewGuid(), "Entrée");
var policyId = Guid.NewGuid();
camera.AssignStoragePolicy(policyId);
camera.StoragePolicyId.ShouldBe(policyId);
}
}