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

38 lines
1.4 KiB
C#
Raw Normal View History

using Heimdall.Application.Common;
using Heimdall.Application.Events.Commands.DeleteEvent;
using Heimdall.Application.Tests.Common;
using Heimdall.Domain.Entities;
using Heimdall.Domain.Enums;
using NSubstitute;
namespace Heimdall.Application.Tests.Handlers.Events;
public class DeleteEventHandlerTests
{
[Fact]
public async Task Delete_event_should_return_success()
{
var ev = new CameraEvent(Guid.NewGuid(), EventType.MotionDetected, 0.9);
var context = Substitute.For<IApplicationDbContext>();
context.CameraEvents.Returns(MockDbSetHelper.CreateFor<CameraEvent>([ev]));
context.SaveChangesWithRetryAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
var handler = new DeleteEventHandler(context);
var result = await handler.Handle(new DeleteEventCommand(ev.Id), CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
}
[Fact]
public async Task Delete_unknown_event_should_return_not_found()
{
var context = Substitute.For<IApplicationDbContext>();
context.CameraEvents.Returns(MockDbSetHelper.CreateFor<CameraEvent>());
var handler = new DeleteEventHandler(context);
var result = await handler.Handle(new DeleteEventCommand(Guid.NewGuid()), CancellationToken.None);
result.IsSuccess.ShouldBeFalse();
result.StatusCode.ShouldBe(404);
}
}