using Heimdall.Application.Common; using Heimdall.Application.Groups.Commands.DeleteGroup; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Groups; public class DeleteGroupHandlerTests { [Fact] public async Task Delete_group_should_return_success() { var group = new Group("Test Group", "Description"); var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor([group])); context.AuditLogs.Returns(MockDbSetHelper.CreateFor()); var handler = new DeleteGroupCommandHandler(context); var result = await handler.Handle(new DeleteGroupCommand(group.Id), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); group.IsDeleted.ShouldBeTrue(); group.DeletedAt.ShouldNotBeNull(); await context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); } [Fact] public async Task Delete_nonexistent_group_should_return_not_found() { var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor([new Group("Test", null)])); var handler = new DeleteGroupCommandHandler(context); var result = await handler.Handle(new DeleteGroupCommand(Guid.NewGuid()), CancellationToken.None); result.IsSuccess.ShouldBeFalse(); result.StatusCode.ShouldBe(404); } }