using Heimdall.Application.Common; using Heimdall.Application.Sites.Commands.DeleteSite; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Sites; public class DeleteSiteHandlerTests { private readonly Site _existingSite = new("Test Site", "Paris", "Europe/Paris"); [Fact] public async Task Delete_site_should_return_success() { var context = Substitute.For(); context.Sites.Returns(MockDbSetHelper.CreateFor([_existingSite])); var handler = new DeleteSiteHandler(context); var command = new DeleteSiteCommand(_existingSite.Id); var result = await handler.Handle(command, CancellationToken.None); result.IsSuccess.ShouldBeTrue(); } [Fact] public async Task Delete_nonexistent_site_should_return_not_found() { var context = Substitute.For(); context.Sites.Returns(MockDbSetHelper.CreateFor([_existingSite])); var handler = new DeleteSiteHandler(context); var command = new DeleteSiteCommand(Guid.NewGuid()); var result = await handler.Handle(command, CancellationToken.None); result.IsSuccess.ShouldBeFalse(); result.StatusCode.ShouldBe(404); } [Fact] public async Task Delete_site_should_soft_delete_and_save() { var context = Substitute.For(); context.Sites.Returns(MockDbSetHelper.CreateFor([_existingSite])); var handler = new DeleteSiteHandler(context); var command = new DeleteSiteCommand(_existingSite.Id); await handler.Handle(command, CancellationToken.None); _existingSite.IsDeleted.ShouldBeTrue(); _existingSite.DeletedAt.ShouldNotBeNull(); await context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); } }