using Heimdall.Application.Common; using Heimdall.Application.Groups.Commands.UpdateGroup; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; using Microsoft.EntityFrameworkCore; namespace Heimdall.Application.Tests.Handlers.Groups; public class UpdateGroupHandlerTests { private readonly Group _group = new("Original Name", "Original description"); [Fact] public async Task Update_group_should_return_success() { var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor([_group])); context.AuditLogs.Returns(MockDbSetHelper.CreateFor()); context.UserGroups.Returns(MockDbSetHelper.CreateFor()); var handler = new UpdateGroupCommandHandler(context); var result = await handler.Handle( new UpdateGroupCommand(_group.Id, "Updated Name", "Updated description"), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.Name.ShouldBe("Updated Name"); await context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); } [Fact] public async Task Update_nonexistent_group_should_return_not_found() { var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor([_group])); var handler = new UpdateGroupCommandHandler(context); var result = await handler.Handle( new UpdateGroupCommand(Guid.NewGuid(), "Name", null), CancellationToken.None); result.IsSuccess.ShouldBeFalse(); result.StatusCode.ShouldBe(404); } }