Files
Heimdall/tests/Heimdall.Application.Tests/Handlers/Groups/DeleteGroupHandlerTests.cs
T

40 lines
1.5 KiB
C#
Raw Normal View History

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<IApplicationDbContext>();
context.Groups.Returns(MockDbSetHelper.CreateFor<Group>([group]));
context.AuditLogs.Returns(MockDbSetHelper.CreateFor<AuditLog>());
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<int>(), Arg.Any<CancellationToken>());
}
[Fact]
public async Task Delete_nonexistent_group_should_return_not_found()
{
var context = Substitute.For<IApplicationDbContext>();
context.Groups.Returns(MockDbSetHelper.CreateFor<Group>([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);
}
}