test(application): add CQRS handler tests for Sites, Cameras, Agents, Auth, Events, Settings, Groups, Users, Assignments, Discovery, Persons, Stats, Audit
2026-07-23 14:32:33 +00:00
|
|
|
using Heimdall.Application.Common;
|
|
|
|
|
using Heimdall.Application.Events.Queries.GetEvent;
|
2026-08-27 20:28:41 +02:00
|
|
|
using Heimdall.Application.Services;
|
test(application): add CQRS handler tests for Sites, Cameras, Agents, Auth, Events, Settings, Groups, Users, Assignments, Discovery, Persons, Stats, Audit
2026-07-23 14:32:33 +00:00
|
|
|
using Heimdall.Application.Tests.Common;
|
|
|
|
|
using Heimdall.Domain.Entities;
|
|
|
|
|
using Heimdall.Domain.Enums;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Application.Tests.Handlers.Events;
|
|
|
|
|
|
|
|
|
|
public class GetEventHandlerTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Get_event_should_return_event_when_found()
|
|
|
|
|
{
|
|
|
|
|
var site = new Site("Test", "Paris", "Europe/Paris");
|
|
|
|
|
var camera = new Camera(site.Id, "Cam-1");
|
|
|
|
|
var ev = new CameraEvent(camera.Id, EventType.MotionDetected, 0.95, DateTime.UtcNow);
|
|
|
|
|
ev.SetCamera(camera);
|
|
|
|
|
|
|
|
|
|
var context = Substitute.For<IApplicationDbContext>();
|
|
|
|
|
context.CameraEvents.Returns(MockDbSetHelper.CreateFor<CameraEvent>([ev]));
|
2026-08-27 20:28:41 +02:00
|
|
|
var cameraAccess = Substitute.For<ICameraAccessService>();
|
|
|
|
|
cameraAccess.HasCameraAccessAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
|
|
|
|
.Returns(true);
|
|
|
|
|
var handler = new GetEventHandler(context, cameraAccess);
|
test(application): add CQRS handler tests for Sites, Cameras, Agents, Auth, Events, Settings, Groups, Users, Assignments, Discovery, Persons, Stats, Audit
2026-07-23 14:32:33 +00:00
|
|
|
|
|
|
|
|
var result = await handler.Handle(new GetEventQuery(ev.Id), CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
result.IsSuccess.ShouldBeTrue();
|
|
|
|
|
result.Data.ShouldNotBeNull();
|
|
|
|
|
result.Data.Id.ShouldBe(ev.Id);
|
|
|
|
|
result.Data.CameraId.ShouldBe(camera.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Get_event_should_return_not_found_when_missing()
|
|
|
|
|
{
|
|
|
|
|
var context = Substitute.For<IApplicationDbContext>();
|
|
|
|
|
context.CameraEvents.Returns(MockDbSetHelper.CreateFor<CameraEvent>());
|
2026-08-27 20:28:41 +02:00
|
|
|
var cameraAccess = Substitute.For<ICameraAccessService>();
|
|
|
|
|
var handler = new GetEventHandler(context, cameraAccess);
|
test(application): add CQRS handler tests for Sites, Cameras, Agents, Auth, Events, Settings, Groups, Users, Assignments, Discovery, Persons, Stats, Audit
2026-07-23 14:32:33 +00:00
|
|
|
|
|
|
|
|
var result = await handler.Handle(new GetEventQuery(Guid.NewGuid()), CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
result.IsSuccess.ShouldBeFalse();
|
|
|
|
|
result.StatusCode.ShouldBe(404);
|
|
|
|
|
}
|
|
|
|
|
}
|