64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
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<Group> _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<IApplicationDbContext>();
|
||
|
|
context.Groups.Returns(MockDbSetHelper.CreateFor<Group>(_groups));
|
||
|
|
context.UserGroups.Returns(MockDbSetHelper.CreateFor<UserGroup>());
|
||
|
|
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<IApplicationDbContext>();
|
||
|
|
context.Groups.Returns(MockDbSetHelper.CreateFor<Group>());
|
||
|
|
context.UserGroups.Returns(MockDbSetHelper.CreateFor<UserGroup>());
|
||
|
|
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<IApplicationDbContext>();
|
||
|
|
context.Groups.Returns(MockDbSetHelper.CreateFor<Group>(_groups));
|
||
|
|
context.UserGroups.Returns(MockDbSetHelper.CreateFor<UserGroup>());
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|