using Heimdall.Application.Common; using Heimdall.Application.Persons.Commands.DeleteFace; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using Microsoft.EntityFrameworkCore; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Persons; public class DeleteFaceHandlerTests { [Fact] public async Task Delete_face_should_return_success() { var face = new KnownFace(Guid.NewGuid(), [0.1f], "thumb.jpg", null); var context = Substitute.For(); context.KnownFaces.Returns(MockDbSetHelper.CreateFor([face])); context.AuditLogs.Returns(Substitute.For>()); var handler = new DeleteFaceCommandHandler(context); var result = await handler.Handle(new DeleteFaceCommand(face.Id), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); await context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); } [Fact] public async Task Delete_nonexistent_face_should_return_not_found() { var context = Substitute.For(); context.KnownFaces.Returns(MockDbSetHelper.CreateFor()); context.AuditLogs.Returns(Substitute.For>()); var handler = new DeleteFaceCommandHandler(context); var result = await handler.Handle(new DeleteFaceCommand(Guid.NewGuid()), CancellationToken.None); result.IsSuccess.ShouldBeFalse(); result.StatusCode.ShouldBe(404); } [Fact] public async Task Delete_face_should_record_audit_log() { var face = new KnownFace(Guid.NewGuid(), [0.1f], "thumb.jpg", null); var context = Substitute.For(); context.KnownFaces.Returns(MockDbSetHelper.CreateFor([face])); context.AuditLogs.Returns(Substitute.For>()); var handler = new DeleteFaceCommandHandler(context); var result = await handler.Handle(new DeleteFaceCommand(face.Id), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); context.AuditLogs.Received(1).Add(Arg.Any()); } }