using Heimdall.Application.Common; using Heimdall.Application.Persons.Queries.GetPersons; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; using Microsoft.EntityFrameworkCore; namespace Heimdall.Application.Tests.Handlers.Persons; public class GetPersonsHandlerTests { [Fact] public async Task Get_persons_should_return_all() { var persons = new List { new("Charlie", "family"), new("Alice", "employee"), new("Bob", "family"), }; var context = Substitute.For(); context.Persons.Returns(MockDbSetHelper.CreateFor(persons)); var handler = new GetPersonsQueryHandler(context); var result = await handler.Handle(new GetPersonsQuery(null), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.Count.ShouldBe(3); } [Fact] public async Task Get_persons_should_filter_by_category() { var persons = new List { new("Charlie", "family"), new("Alice", "employee"), new("Bob", "family"), }; var context = Substitute.For(); context.Persons.Returns(MockDbSetHelper.CreateFor(persons)); var handler = new GetPersonsQueryHandler(context); var result = await handler.Handle(new GetPersonsQuery("family"), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.Count.ShouldBe(2); } [Fact] public async Task Get_persons_empty_should_return_empty_list() { var context = Substitute.For(); context.Persons.Returns(MockDbSetHelper.CreateFor()); var handler = new GetPersonsQueryHandler(context); var result = await handler.Handle(new GetPersonsQuery(null), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldBeEmpty(); } }