2026-07-23 09:52:30 +00:00
|
|
|
using Heimdall.Domain.Entities;
|
|
|
|
|
using Heimdall.Domain.Enums;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Domain.Tests.Entities;
|
|
|
|
|
|
|
|
|
|
public class CameraEventTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Create_event_should_set_properties()
|
|
|
|
|
{
|
|
|
|
|
var cameraId = Guid.NewGuid();
|
|
|
|
|
var evt = new CameraEvent(cameraId, EventType.MotionDetected, 0.95);
|
|
|
|
|
|
|
|
|
|
evt.CameraId.ShouldBe(cameraId);
|
|
|
|
|
evt.Type.ShouldBe(EventType.MotionDetected);
|
|
|
|
|
evt.Confidence.ShouldBe(0.95);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Create_event_with_occurred_at()
|
|
|
|
|
{
|
|
|
|
|
var occurredAt = new DateTime(2026, 7, 1, 12, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.PersonDetected, 0.8, occurredAt);
|
|
|
|
|
|
|
|
|
|
evt.OccurredAt.ShouldBe(occurredAt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Create_event_defaults_occurred_at_to_now()
|
|
|
|
|
{
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.VehicleDetected, 0.5);
|
|
|
|
|
|
|
|
|
|
evt.OccurredAt.ShouldBeLessThanOrEqualTo(DateTime.UtcNow);
|
|
|
|
|
evt.OccurredAt.ShouldBeGreaterThan(DateTime.UtcNow.AddMinutes(-1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SetSnapshot_should_set_urls()
|
|
|
|
|
{
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.MotionDetected, 0.9);
|
|
|
|
|
|
|
|
|
|
evt.SetSnapshot("https://s3.example.com/snap.jpg", "https://s3.example.com/thumb.jpg");
|
|
|
|
|
|
|
|
|
|
evt.SnapshotUrl.ShouldBe("https://s3.example.com/snap.jpg");
|
|
|
|
|
evt.SnapshotThumbUrl.ShouldBe("https://s3.example.com/thumb.jpg");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SetSnapshot_without_thumb_should_not_override()
|
|
|
|
|
{
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.MotionDetected, 0.9);
|
|
|
|
|
evt.SetSnapshot("snap.jpg", "thumb.jpg");
|
|
|
|
|
|
|
|
|
|
evt.SetSnapshot("snap2.jpg");
|
|
|
|
|
|
|
|
|
|
evt.SnapshotUrl.ShouldBe("snap2.jpg");
|
|
|
|
|
evt.SnapshotThumbUrl.ShouldBe("thumb.jpg");
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 20:50:40 +02:00
|
|
|
[Fact]
|
|
|
|
|
public void Stored_snapshot_keeps_its_destination_and_uses_an_authorized_url()
|
|
|
|
|
{
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.PersonDetected, 0.9);
|
|
|
|
|
var location = new StorageLocation(StorageProvider.S3,
|
|
|
|
|
S3Endpoint: "https://objects.example.test", S3Bucket: "heimdall");
|
|
|
|
|
|
|
|
|
|
evt.SetStoredSnapshot($"snapshots/{evt.Id:D}.jpg", location);
|
|
|
|
|
|
|
|
|
|
evt.GetSnapshotLocation().ShouldBe(location);
|
|
|
|
|
evt.SnapshotUrl.ShouldBe($"/api/events/{evt.Id:D}/snapshot/content");
|
|
|
|
|
evt.SnapshotThumbUrl.ShouldBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-23 09:52:30 +00:00
|
|
|
[Fact]
|
|
|
|
|
public void SetMetadata_should_set_label_and_json()
|
|
|
|
|
{
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.FaceRecognized, 0.99);
|
|
|
|
|
var metadata = "{\"bbox\": [100, 200, 300, 400]}";
|
|
|
|
|
|
|
|
|
|
evt.SetMetadata("John Doe", metadata);
|
|
|
|
|
|
|
|
|
|
evt.Label.ShouldBe("John Doe");
|
|
|
|
|
evt.MetadataJson.ShouldBe(metadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AssignAgent_should_set_agent_id()
|
|
|
|
|
{
|
|
|
|
|
var evt = new CameraEvent(Guid.NewGuid(), EventType.MotionDetected, 0.5);
|
|
|
|
|
var agentId = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
evt.AssignAgent(agentId);
|
|
|
|
|
|
|
|
|
|
evt.AgentId.ShouldBe(agentId);
|
|
|
|
|
}
|
|
|
|
|
}
|