Files
Heimdall/tests/Heimdall.Application.Tests/Handlers/Events/GetEventHandlerTests.cs
T

49 lines
1.9 KiB
C#
Raw Normal View History

using Heimdall.Application.Common;
using Heimdall.Application.Events.Queries.GetEvent;
using Heimdall.Application.Services;
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]));
var cameraAccess = Substitute.For<ICameraAccessService>();
cameraAccess.HasCameraAccessAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(true);
var handler = new GetEventHandler(context, cameraAccess);
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>());
var cameraAccess = Substitute.For<ICameraAccessService>();
var handler = new GetEventHandler(context, cameraAccess);
var result = await handler.Handle(new GetEventQuery(Guid.NewGuid()), CancellationToken.None);
result.IsSuccess.ShouldBeFalse();
result.StatusCode.ShouldBe(404);
}
}