using Heimdall.Application.Cameras.Commands.DeleteCamera; using Heimdall.Application.Common; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Cameras; public class DeleteCameraHandlerTests { private readonly Camera _existingCamera = new(Guid.NewGuid(), "Front Door"); [Fact] public async Task Delete_camera_should_return_success() { var context = Substitute.For(); context.Cameras.Returns(MockDbSetHelper.CreateFor([_existingCamera])); var handler = new DeleteCameraCommandHandler(context); var command = new DeleteCameraCommand(_existingCamera.Id); var result = await handler.Handle(command, CancellationToken.None); result.IsSuccess.ShouldBeTrue(); } [Fact] public async Task Delete_nonexistent_camera_should_return_not_found() { var context = Substitute.For(); context.Cameras.Returns(MockDbSetHelper.CreateFor([_existingCamera])); var handler = new DeleteCameraCommandHandler(context); var command = new DeleteCameraCommand(Guid.NewGuid()); var result = await handler.Handle(command, CancellationToken.None); result.IsSuccess.ShouldBeFalse(); result.StatusCode.ShouldBe(404); } [Fact] public async Task Delete_camera_should_soft_delete_and_save() { var context = Substitute.For(); context.Cameras.Returns(MockDbSetHelper.CreateFor([_existingCamera])); var handler = new DeleteCameraCommandHandler(context); var command = new DeleteCameraCommand(_existingCamera.Id); await handler.Handle(command, CancellationToken.None); _existingCamera.IsDeleted.ShouldBeTrue(); _existingCamera.DeletedAt.ShouldNotBeNull(); await context.Received(1).SaveChangesAsync(Arg.Any()); } }