using NSubstitute; using TeleWave.Application.Admin.Users.ListUsers; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Models; using Xunit; namespace TeleWave.Application.Tests.Admin; /// /// Список пользователей: хендлер только перекладывает параметры запроса в порт — Identity живёт /// вне IAppDbContext. Проверяется именно перекладка: потерянный фильтр здесь означал бы /// заблокированных вперемешку с активными. /// public class ListUsersTests { [Fact] public async Task PassesEveryFilterToIdentityService() { var identity = Substitute.For(); var roleId = Guid.NewGuid(); var page = new PagedList([], 0, 2, 25); identity .ListUsersAsync(Arg.Any(), Arg.Any()) .Returns(page); var result = await new ListUsersQueryHandler(identity).Handle( new ListUsersQuery(2, 25, "иван", roleId, IsBlocked: true, Sort: "created", Desc: true), CancellationToken.None ); Assert.Same(page, result); await identity .Received(1) .ListUsersAsync( new UserListFilter(2, 25, "иван", roleId, true, "created", true), Arg.Any() ); } [Fact] public async Task DefaultsSortAndDirection_WhenNotAsked() { var identity = Substitute.For(); identity .ListUsersAsync(Arg.Any(), Arg.Any()) .Returns(new PagedList([], 0, 1, 20)); await new ListUsersQueryHandler(identity).Handle( new ListUsersQuery(1, 20, null, null, null), CancellationToken.None ); await identity .Received(1) .ListUsersAsync( Arg.Is(f => f.Sort == null && !f.Desc && f.Search == null), Arg.Any() ); } }