using Heimdall.Application.Common; using Heimdall.Application.DTOs; using Heimdall.Application.Groups.Queries.GetGroups; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; using Microsoft.EntityFrameworkCore; namespace Heimdall.Application.Tests.Handlers.Groups; public class GetGroupsHandlerTests { private readonly List _groups = [ new Group("Beta", null), new Group("Alpha", null), new Group("Gamma", null), ]; [Fact] public async Task Get_groups_should_return_paginated_results() { var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor(_groups)); context.UserGroups.Returns(MockDbSetHelper.CreateFor()); var handler = new GetGroupsQueryHandler(context); var result = await handler.Handle(new GetGroupsQuery(1, 10), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.Items.Count.ShouldBe(3); result.Data.TotalCount.ShouldBe(3); } [Fact] public async Task Get_groups_empty_result_should_return_empty_list() { var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor()); context.UserGroups.Returns(MockDbSetHelper.CreateFor()); var handler = new GetGroupsQueryHandler(context); var result = await handler.Handle(new GetGroupsQuery(1, 10), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data!.Items.ShouldBeEmpty(); } [Fact] public async Task Get_groups_should_respect_pagination() { var context = Substitute.For(); context.Groups.Returns(MockDbSetHelper.CreateFor(_groups)); context.UserGroups.Returns(MockDbSetHelper.CreateFor()); var handler = new GetGroupsQueryHandler(context); var result = await handler.Handle(new GetGroupsQuery(1, 2), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data!.Items.Count.ShouldBe(2); result.Data.TotalCount.ShouldBe(3); } }